[Haskell-cafe] Monad layering and DSL

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sun Jan 25 08:37:38 UTC 2015

On Sat, Jan 24, 2015 at 07:46:52PM +0100, Gautier DI FOLCO wrote:
> data ImapF next =
>          Select DirectoryName (Maybe DirectoryDescription -> next)
>        | Noop (DirectoryDescription -> next)
>        | Search MailSearch (Maybe [UID] -> next)
> -- Functor instance
> type Imap = Free ImapF
> searchAll :: Imap (Maybe [UID])
> searchAll = liftF $ Search undefined id
> select :: DirectoryName -> Imap (Maybe DirectoryDescription)
> select directory = liftF $ Select directory id
> My main problem is the following: if I do a select of an unknown directory,
> I should stop the computation.

What do you mean you "should stop the computation"?  Do you mean the
interpretation of the free monad should be forced to stop?  If so, doesn't
making the type of the `Select` constructor

    Select DirectoryName (DirectoryDescription -> next)

achieve this?  That way if the interpreter talks issues a select command to
the server and fails to receive a `DirectoryDescription` in return then it
is forced to stop.


More information about the Haskell-Cafe mailing list