[Haskell-cafe] Evaluating arithmetic expressions at run time

Andrew Savige ajsavige at yahoo.com.au
Sat Jan 28 01:30:02 EST 2006


Haskell beginner using GHC.

I have a function to do some simple arithmetic at run time:

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

While that works, I'm curious to know if it can be done more
elegantly. I'm thinking of something like:

myeval :: Int -> Int -> String -> Int
myeval x y op = (read op) x y

Thanks,
/-\



		
____________________________________________________ 
Do you Yahoo!? 
Listen to over 20 online radio stations and watch the latest music videos on Yahoo! Music. 
http://au.launch.yahoo.com


More information about the Haskell-Cafe mailing list