BTW: There isn't an easy way to magically derive opTable. We're relying on the fact that these simple functions all have the same type.

Ben Lippmeier wrote:

opTable
 = [ ("+", (+))
   , ("-", (-)) ... ]

myeval x y op
 = let    Just fun = lookup op opTable
   in   x `fun` y



You could also do

myeval x y op
 = case op of
        "+"   -> x + y
        "-"   -> x - y
...

is probably the "smallest" way.

Ben.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to