title: Evaluation of Haskell Statements/Expressions using GHC API
body: <p>For a tool I'm writing ( <a href="http://hackage.haskell.org/package/explore" rel="noreferrer">http://hackage.haskell.org/package/explore</a> ) I need a way to read haskell function definitions at run-time, apply them to values from my tool and retrieve the results of their application.</p>
  
  <p>Can anyone give me a very basic example using GHC (6.10.4 or 6.12.1) API?</p>
  
  <p>example function definition to be read from a file at run-time:</p>
  
  <pre><code>f x = 10**(4/1102*x - 1)
  </code></pre>
  
  <p>expected program output</p>
  
  <pre><code>--mapM_ print $ map f [428, 410, 389]
  3.577165388142748
  3.077536885227335
  2.5821307011665815
  </code></pre>
  
  <p><strong>!!UPDATE!!</strong>
  <br />
  I posted a quick answer but it creates an object file in the directory of execution, any tips to avoid this and avoid all file IO is most welcome. I want to also see a version that does everything in memory: user provides the function definition in a GUI for example and the compilation / evaluation does not create any object files.</p>