Comparison of prompt and free monads.
The prompt monad is a free monad but with a more convenient programming interface in the context of designing EDSLs. It also predates free monads as far as the Haskell community is concerned.
Prompt, one defines an API GADT
API r where each constructor takes the parameters of an API function as arguments, and specifies its result type in
In contrast, for
Free, one needs to define a functor; each constructor takes the arguments of an API function as parameters, and in addition a continuation that is a function from the result type to a value of th functor's argument type.
ExFree for examples. Note that the
Prompt code is slightly less cluttered and thus a bit simpler. So for implmenting EDSLs, which are usually thought of as an API, prompt monads are more convenient.
Relation between prompt and free monads
Free are universal monad. Basically,
Prompt p a is isomorphic to
Free (PromptF p) a where
data PromptF p a where PromptF :: p r -> (r -> a) -> PromptF p a
Free f a is isomorphic to
Prompt (FreeP f) a where
data FreeP f a where FreeP :: f a -> FreeP f a
As far as I know, the arrival of
MonadPrompt predates the popularization of free monads in the Haskell community by a couple of months, see the links below. In fact, some early discussion on the topic of universality revolved around a universal monad called
Unimo that has long been forgotten, rather than free monads.
- original description (Ryan Ingram, 2007-11-18)
- continuations (apfelmus + Bertram Felgenhauer, 2008-01-18)
- discussion of Unimo (but there was more, leading up to
RecPrompttype to capture continuations)
- MonadPrompt (Hackage, uploaded 2008-03-20)
- Monads for Free (Comonad reader, 2008-04-11)
- free (Hackage, uploaded 2011-02-17)
- free monads are free (There must be a better link)