[Haskell-cafe] Re: Metaprogramming in Haskell vs. Ocaml

Nicolas Pouillard nicolas.pouillard at gmail.com
Tue Apr 6 09:23:09 EDT 2010


On Tue, 06 Apr 2010 15:08:45 +0200, Heinrich Apfelmus <apfelmus at quantentunnel.de> wrote:
> Jacques Carette wrote:
> > Jason Dagit wrote:
> >> Are you implying that template haskell is not typed?
> >
> > Indeed. [...]
> >
> > Compare with metaocaml where if you can compile you meta-program (i.e.
> > code generator), then you are guaranteed that it can only ever produce
> > valid, well-typed code.  Not so with TH, where you can easily generate
> > junk -- which GHC will promptly figure out  and give you an error.
> 
> I'm curious, can metaocaml create new data type definitions, value
> declarations or type class instances? I usually use TH to get rid of
> boilerplate that I cannot get rid off in Haskell itself, for instance
> for creating functional lenses for record types
> 
>     data Foo = Foo { bar_ :: Int, ...}
> 
>     $(DeriveLenses Foo)
>     -- bar :: Lens Foo Int

No metaocaml cannot do this. It is restricted to the expression level, and
not the declaration level. Moreover you cannot pattern match over the
generated code.

> It seems to me that metaocaml is more used as "user annotated" partial
> evaluation?

That is a way to look at it.

-- 
Nicolas Pouillard
http://nicolaspouillard.fr


More information about the Haskell-Cafe mailing list