I have a Haskell Map, containing strings as keys and some lambda functions as items . Eg.:
-- List of supported Operators -> mapping with functions ops = Map.fromList [("+", \x y -> x + y), ("-", \x y -> y - x), ("*", \x y -> x * y), ("/", \x y -> y / x)]
I want to write a function that takes as input:
- A string representing an operator ["+", "-", "*", "/"]
- Two numbers
Based on the operator and the ops map, the function will evaluate the sum/subtraction/etc. of the two numbers .
I've tried something like:
(Map.lookup "+" a) 1 2
But it's not working .
The error is:
Top level: No instance for (Show (Integer -> Integer)) arising from use of `print' at Top level Probable fix: add an instance declaration for (Show (Integer In a 'do' expression: print it <interactive>:1:1: No instance for (Monad ((->) t)) arising from use of `Data.Map.lookup' at <interactive>:1:1- Probable fix: add an instance declaration for (Monad ((->) t) In the definition of `it': it = (Data.Map.lookup "+" a) 1 2
... not very helpful for me.
Any suggestions ? Thank you !