Postlude

We have covered the basics and monads. There’s a lot more to functional programming and Haskell!

Overview of Monoids, Foldable, and Traversable

Writer and Reader

type    State  s   a  =                          s -> (a, s  )
type    Reader env a  =                        env ->  a
type    Writer log a  =                               (a, log)

newtype State  s   a  =  State  { runState  ::   s -> (a, s  ) }
newtype Reader env a  =  Reader { runReader :: env ->  a       }
newtype Writer log a  =  Writer { runWriter ::        (a, log) }

State s a    values produce an a… while also reading and “updating mutable state” of type s.

Reader env a values produce an a… while also accessing some (read-only) environment.

Writer log a values produce an a… plus a “log” (often a String or list but in general any Monoid).

Monad vs Applicative “Pipelines”

Maybe Monad Transformer…

newtype MaybeT    m a = MaybeT  { runMaybeT  :: m (Maybe a)   }
newtype StateT  s m a = StateT  { runStateT  :: s -> m (a, s) }
newtype ReaderT r m a = ReaderT { runReaderT :: r -> m a      }
newtype WriterT w m a = WriterT { runWriterT :: m (a, w)      }

State Monad Transformer

newtype StateT s m a =
  StateT { runStateT :: s -> m (a, s) }

type State    s a = StateT  s          Identity a
type Parser     a = StateT  String     []       a
type NState   s a = StateT  s          []       a
type NState01 s a = StateT (s, StdGen) Maybe    a

Laziness and Seq

Mutable State (if you’re “overly attached” or actually require it)

Zippers

Lens: Lenses, Folds, and Traversals

Generalized Algebraic Datatypes (GADTs)

QuickCheck: Randomized Property-Based Testing

🎆 Fireworks, courtesy of Logan Quick! 🎆