Tue Aug 2 14:15:49 CEST 2011

Awesome Prelude

Funny that in the "JavaScript types" example in [2] the same mechanism
of language-specific type constructors using phantom types is used as
in the tagless paper[4].

The general idea of replacing datatypes with type classes is to
abstract what you want to do with it.  For data types this is
construction and destruction.  For the BoolC class the constructors
are `true' and `false' while `bool' is the destructor.

  data Bool

  class BoolC dsl where
    false :: dsl Bool
    frue  :: dsl Bool
    bool  :: dsl a -> dsl a -> dsl Bool -> dsl r

Here the `dsl' parameter is the parameterized type constructor for
the DSL that implements the BoolC class.

The cool thing is that the same strategy works for functions

  class FunC dsl where
    lam :: (dsl a -> dsl b) -> dsl (a -> b)
    app :: dsl (a -> b) -> dsl a -> dsl b

Here `lam' takes a Haskell function and maps it to a function in the
DSL representation, and `app' does the reverse.

The downside is no syntactic support, which makes it difficult to use
in practice.  The best approach atm seems to be to write an explicit
syntactic frontend when your're designing a language to sidestep these

[1] http://tom.lokhorst.eu/media/presentation-awesomeprelude-dhug-feb-2010.pdf
[2] http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video
[3] https://github.com/tomlokhorst/AwesomePrelude
[4] http://www.cs.rutgers.edu/~ccshan/tagless/jfp.pdf