question on the design of protohaskell (in Write You a Haskell)

I know this part has been left incomplete when Stephen got a real job, but I have a question. In http://dev.stephendiehl.com/fun/007_path.html, compiler steps are piped together using the Kleisli (>=>) operator, presumably the one from Control.Monad. 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)? Or is the intention to have a special >=> that also updates the state (but I wouldn't know how to deal w/ Syn.Core vs Core.Module) I would understand some form of phantom type to ensure that compilation steps are in the right order, but as it is I'm puzzled. Anybody has some insight? Thanks, Maurizio

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 exceptions.
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)?
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
In CompilerState there is a field _ast :: Maybe Syn.Module -- ^ Frontend AST 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. Tom
participants (2)
-
Maurizio Vitale
-
Tom Ellis