Re: [Haskell-cafe] Downsides of the Prompt Monad

David Menendez wrote
It's worth noting that Prompt p is the free monad for a type constructor p, just as Free f is the free monad for a Functor f. As such, when p is a Functor, they are isomorphic.
data Free f a = Var a | Wrap (f (Free f a)) newtype Prompt p a = Prompt { unPrompt :: forall b. (forall i. p i -> (i -> b) -> b) -> (a -> b) -> b } -- equivalently, Prompt p a = Done a | forall i. Prompt (p i) (i -> Prompt p a)
Indeed. The Freer monad paper, Sec 2.4, describes this correspondence in general: type FFree p = Free (Lan p) (FFree p is the alternative Prompt p in David's message) where Lan p is a (simple version) of the left Kan extension that turns any p :: * -> * into a functor. Once (Lan p) is a Functor, the standard free monad construction applies. The Freer monad paper then goes on to say that since the continuation is made explicit, it can be represented in a better way than just a function.
participants (1)
-
Oleg