Hello everybody,

The concept of reflection can also be taken further than Chris' idea, which
is fairly useful in it's own right, but could possibly be achieved by some
smart FFI-wizard (not sure, this idea just popped into my head).

What I'm getting at is some kind of way to get your hands on an abstract 
syntax representation of a Haskell expression/datatype/module, modifying it,
re-typechecking it, and then transforming it back into a Haskell value. 
This probably would entail carrying Hugs around in the runtime-system and I 
can imagine you need some kind of monad to protect against unwanted effects.

Then you could do things like:

module CheckPartition where
import HaskellAST
import HaskellReflection

check :: Reflection String
check = do (Binding name body) <- getBindingFromString "partition"
           if body /= haskellParse "\p xs -> (filter p xs,filter (not.p) xs)"
            then return "Read up on the Haskell mailing list!"
            else return "Way to go!"

main = do string <- refl2IO check
          putStr string

The possibilities are endless...

A fixed(ie standardized) HaskellAST module would be great since every wannabe 
compiler writer seems to write of her/his own (I know I do!). Maybe that 
Reflection stuff is slightly unrealistic though...

All the best,

Jan de Wit


Reply via email to