Andrew Savige wrote:
--- Cale Gibbard wrote:
Apart from moving to a lookup Map or something, a simple reordering
of the arguments allows you to shorten things up a bit:

myeval :: String -> Int -> Int -> Int
myeval "+" = (+)
myeval "-" = (-)
myeval "*" = (*)
etc.

Thanks to all for the excellent suggestions. I'm liking the
Haskell version of this function a lot more now. :-)

To help me learn Haskell, I'm converting a small Ruby
program to Haskell. In Ruby this can be done in one line:

def myeval(x, y, op)
  x.send op, y
end

This could be done in Haskell by

myeval :: a->b->(a -> b -> c) -> c
myeval x y op = op x y

eg myeval (+) 1 2

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

Reply via email to