
28 Jan
2006
28 Jan
'06
6:39 a.m.
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.