[Haskell-cafe] Evaluating arithmetic expressions at run time
Henning Thielemann
lemming at henning-thielemann.de
Sun Jan 29 15:54:34 EST 2006
On Sat, 28 Jan 2006, Andrew Savige wrote:
> 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
> -- ...
Additionally to the other suggestions, I advise using a custom type
data Op = Add | Sub | Mul
instead of String, if possible.
More information about the Haskell-Cafe
mailing list