[Haskell-cafe] Re: Monadic bind with associated types + PHOAS?
ccshan at post.harvard.edu
Wed Nov 19 13:03:40 EST 2008
Ryan Ingram <ryani.spam at gmail.com> wrote in article <2f9b2d30811190316o7d24cfccl235fafcf26d17a73 at mail.gmail.com> in gmane.comp.lang.haskell.cafe:
> I really like the syntax for do-notation. And I really like how great
> Haskell is as writing embedded languages, a lot of which comes from
> the "programmable semicolon" that monadic bind gives you.
AFAICT, standard Haskell 98 already gives you the ability to express
binding and sharing in PHOAS, except not using do-notation:
class Symantics repr where
lam :: (repr a -> repr b) -> repr (a -> b)
app :: repr (a -> b) -> repr a -> repr b
add :: repr Int -> repr Int -> repr Int
int :: Int -> repr Int
let_ :: Symantics repr => repr a -> (repr a -> repr b) -> repr b
let_ e body = app (lam body) e
testSharing :: Symantics repr => repr Int
testSharing = let_ (add (int 3) (int 4)) (\x -> add x x)
Oleg has already noted that you can nicely express the showing,
optimization (such as partial evaluation), and transformation (such as
to CPS) of embedded code in this framework. I agree with him and you
that this representation is a promising direction to explore.
All that's missing in standard Haskell 98, then, is the ability to use
(>>=) = let_
testSharing = do x <- add (int 3) (int 4)
add x x
But -XNoImplicitPrelude in GHC 6.10 is supposed to enable it, no?
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
2008-11-20 Universal Children's Day http://unicef.org/
1948-12-10 Universal Declaration of Human Rights http://everyhumanhasrights.org
More information about the Haskell-Cafe