Tutorial by Examples

For instance, a computation involving commands to read and write from the prompt: First we describe the "commands" of our computation as a Functor data type {-# LANGUAGE DeriveFunctor #-} data TeletypeF next = PrintLine String next | ReadLine (String -> next) derivin...
Compare the definition of Free to that of Fix: data Free f a = Return a | Free (f (Free f a)) newtype Fix f = Fix { unFix :: f (Fix f) } In particular, compare the type of the Free constructor with the type of the Fix constructor. Free layers up a functor just like Fix, except ...
There are some functions to help tear down Free computations by interpreting them into another monad m: iterM :: (Functor f, Monad m) => (f (m a) -> m a) -> (Free f a -> m a) and foldFree :: Monad m => (forall x. f x -> m x) -> (Free f a -> m a). What are they doing? First l...
There's an alternative formulation of the free monad called the Freer (or Prompt, or Operational) monad. The Freer monad doesn't require a Functor instance for its underlying instruction set, and it has a more recognisably list-like structure than the standard free monad. The Freer monad represents...

Page 1 of 1