Skip to content

ArulselvanMadhavan/haskell-first-principles

Repository files navigation

Haskell Handbook

Add package

stack install QuickCheck

Load Tests

stack ghci <project_name>:<test_module_name>

To make GHC notice changes to package.yaml

stack build

To enable QuasiQuotes

:set -ddump-splices

Monoid

Applied on a per operation basis

  1. Binary
  2. Associative
  3. Idenity

Semigroup

A monoid where the Identity property is left out.

Magma

Magma < Semigroup < Monoid

Functor

A way to apply a function over or around some structure that we don't want to alter.

Functor laws - <$> - Function application over a structure

fmap id = id
fmap (p . q) = (fmap p) . (fmap q)

Functor instances are unique for a given datatype as opposed to monoid which is unique per operation.

QuickCheck

  1. Arbitrary typeclass is used for generating values
  2. CoArbitrary typeclass is used for generating functions

Applicative

  1. Applicatives are monoidal functors.
class Functor f => Applicative f where
      pure :: a -> f a
      <*>  :: f (a -> b) -> f a -> f b
  1. <*> - is called "apply".
  2. Comparison with Functor
(<$>) :: Functor f
      => (a -> b) -> f a -> f b
(<*>) :: Applicative f
      => f (a -> b) -> f a -> f b

Applicative Laws

  1. Identity
pure id <*> v = v
  1. Composition
pure (.) <*> u <*> v <*> w =
     u <*> (v <*> w)
  1. Homomorphism
pure f <*> pure x = pure (f x)
  1. Interchange
u <*> pure y = pure ($ y) <*> u
  1. Applicative is just function application that preserves without doing anything other than combining the structure bits.
  2. Applicative can have more than one valid and lawful instance for a given datatype.
Applicative can be thought of characterizing Monoidal Functors in Haskell

Monad

Notes on Monad

Foldable

Notes on Foldable

Traversable

Notes on Traversable

TODO

  1. I haven't done Chapter16 Chapter Exercise 11.
  2. Chapter 21 - Tests for Exercise SkiFree are failing.
  3. Chapter 21 - Need to write Arbitrary Instance for Tree and finish the test.

Releases

No releases published

Packages

No packages published