Elias Hernandis - 21 Jan 2020

The inner workings of QuickTest do not really matter. The important thing is coming up and writting properties to verify correctness.

Remember to explicitly write the types of the predicates so that QuickCheck can provide appropriate examples.

An expression is in WHNF if any of the following are true:

- The expression is a
**constructor**;- If the expression is a constructor that is being pattern matched on (e.g. a constructor inside a
`case ... of`

, then it will be reduced depending on the value of the constructor.

- If the expression is a constructor that is being pattern matched on (e.g. a constructor inside a
- The expression is an
**anonymous function**, i.e. a lambda expression;- If lambda is being applied to all of its arguments, then it is reduced depending on their value.

- The expression is a
**function applied to too few arguments**.

- Generalisation of
`map`

for arbitrary containers **Examples:**`[]`

(List) where`fmap = map`

,`Maybe`

where`fmap ≠ mapMaybe`

, but rather`fmap f Nothing = Nothing, fmap f (Just x) = f x`

, and`IO`

where`fmap`

comes from the`IO`

Monad.

- There is an alias for
`fmap`

namely`<$>`

, e.g.`map (+1) [1..3] == (+1) <$> [1..3]`

.

- Sometimes called
*Applicative functor* - Found in the
`Control.Applicative`

module. **Examples:**`Maybe`

`List`

`IO`

`liftA2 :: (Applicative f) => (a -> b -> c) -> f a -> f b -> f c`

takes a binary function an*lifts*it to a function that operates on two functors.

```
class Monoid a where
mempty :: a
mappend :: a -> a -> a
mconcat :: [a] -> a
mconcat = foldr mconcat mempty
```

- We often write
`mappend`

using infix notation with`<>`

.

```
-- mempty is the identity element for <>
mempty <> x = x
x <> mempty = x
-- The <> operator is left and right associative
(x <> y) <> z = x <> (y <> z)
```

Remember that each do block maps to a monad, and some monads don’t do what we intuitively think they do. Consider

where the list monad comes into place (think of

**list comprehensions**in this case).