title: Compile Haskell programs to LLVM IR
body: <p>According to <a href="https://stackoverflow.com/questions/52037888/compile-haskell-programs-to-c">this SO post</a> compilation of Haskell programs to C is no longer (officially) supported. So I wanted to explore the option of compiling Haskell programs to LLVM IR. I chose the same program of the mentioned post:</p>
  
  <pre><code>quicksort [] = []
  quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
    where
      lesser  = filter (&lt;  p) xs
      greater = filter (&gt;= p) xs
  
  main = print(quicksort([5,2,1,0,8,3]))
  </code></pre>
  
  <p>and then tried to compile it to LLVM IR with:</p>
  
  <pre><code>$ ghc -fllvm main.hs
  </code></pre>
  
  <p>Then I get this error regarding the LLVM version:</p>
  
  <pre><code>&lt;no location info&gt;: error:
      Warning: Couldn't figure out LLVM version!
               Make sure you have installed LLVM 3.7
  ghc: could not execute: opt-3.7
  </code></pre>
  
  <p>When I check my opt version it's 3.8.0, which is bigger:</p>
  
  <pre><code>$ opt --version
  LLVM (http://llvm.org/):
    LLVM version 3.8.0
    DEBUG build with assertions.
    Built Jun 20 2018 (14:59:34).
    Default target: x86_64-unknown-linux-gnu
    Host CPU: broadwell
  </code></pre>
  
  <p>So what's going on? <strong>could ghc expect exactly version 3.7.0 and only that?!</strong></p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>After installing llvm 3.7.0 and copying <code>opt</code> and <code>llc</code> to have 3.7 suffixes:</p>
  
  <pre><code>$ cp opt opt-3.7
  $ cp llc llc-3.7
  </code></pre>
  
  <p>compilation to llvm goes without errors, using this line:</p>
  
  <pre><code>$ ghc -keep-llvm-files main.hs
  </code></pre>
  
  <p>and a file called main.ll is created.</p>