
--- 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 I had a feeling this sort of dynamic sending of messages to objects at run time was impossible in Haskell, hence my question. What I'm still unsure about is why this sort of thing is impossible in Haskell. Is it a fair comment to state that this sort of thing is impossible in Haskell as a consequence of its static typing? Or could it be done in a static typed language with more run time support? Despite being longer, overall I prefer the Haskell version because it is faster and "safer" (in that a number of run time errors in the Ruby version are caught at compile time in the Haskell version). /-\ ____________________________________________________ Do you Yahoo!? Find a local business fast with Yahoo! Local Search http://au.local.yahoo.com