[Haskell-cafe] "quoting" in Haskell

Peter Verswyvelen bf3 at telenet.be
Mon Aug 27 11:04:17 EDT 2007


In Scheme, on can "quote" code, so that it becomes data. Microsoft's F# 
and C# 3.0 also have something similar that turns code into "expression 
trees". The latter is used extensively in LINQ which translates plain C# 
code into SQL code or any other code at runtime (this idea came from FP 
I heared)

I can't find something similar for Haskell? Maybe I am looking at the 
wrong places?

In Haskell, I know one can use a data constructor as a function (as in 
(map Just [1..3])), but a function cannot be turned into a data 
constructor (= "quoting"), can it?

Now this is all really fuzzy for a newbie like me, because aren't all 
functions initially just data constructors waiting to be evaluated in a 
lazy language?

I'm actually looking for something like (loose terminilogy follows) 
"context-based-semi-quoting". The idea is to only quote a set of 
functions, while evaluating all the others.

For example, in the code

1 `add` 2 `mul` 3
where
    add = (+)
    mul = (*)

I want to write something like

selectiveQuote [add] (1 `add` 2 `mul` 3)

which would result in an expression tree like

   add
  /      \
1        6

So the `mul` is not quoted because it is not part of the "context" = [add]

Maybe this is just impossible, I did not dig deep into this.

Thanks,
Peter



More information about the Haskell-Cafe mailing list