[Haskell-cafe] Monad for HOAS?

Lauri Alanko la at iki.fi
Wed May 14 11:25:55 EDT 2008

On Wed, May 14, 2008 at 03:59:23PM +0100, Edsko de Vries wrote:
> You mention that a "direct" implementation of what I suggested would
> break the monad laws, as (foo) and (Let foo id) are not equal. But one
> might argue that they are in fact, in a sense, equivalent. Do you reckon
> that if it is acceptable that foo and do { a <- foo; return a } don't
> return equal terms (but equivalent terms), we can do still better?

If you just want the syntactic sugar and don't care about monads, in
GHC you can use plain do-notation:

{-# OPTIONS -fno-implicit-prelude #-}

import Prelude hiding ((>>=), fail)

data Expr = One | Add Expr Expr | Let Expr (Expr -> Expr)

(>>=) = Let

fail = error

t :: Expr
t = do a <- One
       b <- Add a a
       Add b b

That's generally pretty icky, though.


More information about the Haskell-Cafe mailing list