stack install QuickCheck
stack ghci <project_name>:<test_module_name>
stack build
:set -ddump-splices
Applied on a per operation basis
- Binary
- Associative
- Idenity
A monoid where the Identity property is left out.
Magma < Semigroup < Monoid
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
- Arbitrary typeclass is used for generating values
- CoArbitrary typeclass is used for generating functions
- Applicatives are monoidal functors.
class Functor f => Applicative f where
pure :: a -> f a
<*> :: f (a -> b) -> f a -> f b
- <*> - is called "apply".
- Comparison with Functor
(<$>) :: Functor f
=> (a -> b) -> f a -> f b
(<*>) :: Applicative f
=> f (a -> b) -> f a -> f b
- Identity
pure id <*> v = v
- Composition
pure (.) <*> u <*> v <*> w =
u <*> (v <*> w)
- Homomorphism
pure f <*> pure x = pure (f x)
- Interchange
u <*> pure y = pure ($ y) <*> u
- Applicative is just function application that preserves without doing anything other than combining the structure bits.
- Applicative can have more than one valid and lawful instance for a given datatype.
Applicative can be thought of characterizing Monoidal Functors in Haskell
- I haven't done Chapter16 Chapter Exercise 11.
- Chapter 21 - Tests for Exercise SkiFree are failing.
- Chapter 21 - Need to write Arbitrary Instance for Tree and finish the test.