[Haskell-cafe] question on the design of protohaskell (in Write You a Haskell)

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Jan 23 11:00:47 UTC 2016

On Fri, Jan 22, 2016 at 02:38:38PM -0500, Maurizio Vitale wrote:
> In http://dev.stephendiehl.com/fun/007_path.html compiler steps are piped
> together using the Kleisli (>=>) operator, presumably the one from
> Control.Monad.

Yes, it uses the Monad instance of CompilerMonad, which is

    type CompilerMonad = ExceptT Msg (StateT CompilerState IO)

so the monad can do IO, read and modify the CompilerState, and throw Msg

> they also return some flavour of AST (typically Syn.Module or Core.Module).
> Assuming that the >=> is the one from Control.Monad, what is the purpose of
> this returned value (all the steps are in a compilerMonad and presumably
> would have to update the state w/ the new AST anyhow)?

In CompilerState there is a field

    _ast      :: Maybe Syn.Module    -- ^ Frontend AST

>From the comment I presume this is the AST taken directly from the source
file, to be used for error-reporting and such.  I would guess after the
parseP stage it doesn't change, and the result of each stage is the
Syn.Module returned from that stage not something set in the monad.


More information about the Haskell-Cafe mailing list