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