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

Jacques Carette carette at mcmaster.ca
Tue Apr 6 09:37:59 EDT 2010


One thing I should have mentionned - TH and camlp4 are really 
equivalents.  And camlp4 is as-typed-as TH (or not, depending on your 
point of view).  I am co-author of a camlp4 extension, and I must admit 
that coding in camlp4 was not enjoyable, while coding in metaocaml 
(eventually) is.

[I see that Nicolas Pouillard just answered the question about new type 
definitions, etc, as I was typing this answer]

Heinrich Apfelmus wrote:
> It seems to me that metaocaml is more used as "user annotated" partial
> evaluation?
>   
I see most of my uses of metaocaml as code generation (building 'up' 
code from pieces by making explicit design choices) rather than 
classical partial evaluation (specializing code).  Others would argue 
that these two activities are really the same thing -- and I would not 
really disagree!  It's just that in my cases the 'specialization' is not 
driven by the partial evaluator at all, it is fully driven by the user 
[through explicit decisions of which modules/functors to use].  This 
requires a very different code organization, which is why I make the 
difference between the two approaches.

The Haskell analogy: I write tons and tons of typeclass-level 'code', 
including typeclasses for type constructors (and type constructor 
transformers and ...) but then I ensure that whenever these are used, it 
can be statically determined exactly which instance should be used, and 
100% of the dispatch overhead is eliminated AND I get full control over 
which methods get inlined in the final code.  It is that 'full control' 
aspect which gets you reliable efficiency from highly abstract code.

Jacques


More information about the Haskell-Cafe mailing list