Syntax extensions: mdo and do...rec

Ross Paterson ross at soi.city.ac.uk
Thu Sep 18 01:18:13 EDT 2003


The arguments being made here can all be found in the recursive monad
bindings papers and Levent's thesis.

On Wed, Sep 17, 2003 at 11:41:24AM -0700, Brandon Michael Moore wrote:
> In any case, I don't see the need for explicit rec groups. Can't GHC just
> find the strongly connected components like it already does with let
> bindings?

That's what GHC and Hugs do now for mdo (actually segments rather than
components, because actions can't be rearranged).

> Don't the laws for loop and mfix justify the transformation?

The loop axioms do, but Levent didn't assume right tightening, which
corresponds to moving bindings down from a rec, because monads like
exceptions don't satisfy it.  The same would go for a loop defined on
an exception arrow.  And that's the biggest problem with implicit
segmentation: you need to understand what it does to work out the
meaning of your program.  Again there's an example in those papers
and Levent's thesis.

BTW, in GHC 6.2 with the -fglasgow-exts -farrows flags, you will be able
to use either mdo or do...rec for monads and for arrows, as an experiment.
(Maybe "rec" wasn't such a great keyword to take from the identifier
space.)


More information about the Haskell mailing list