LLVM bindings for Haskell

The Haskell bindings to LLVM have been updated in Arch. You can also use the Hackage package, or get it from darcs.

This version of the package appears to add some new safety via type-level library:

This library permits performing computations on the type-level. Type-level functions are implemented using functional dependencies of multi parameter type classes. To date, Booleans and Numerals (Naturals and Positives) are supported. With regard to Numerals, there is support for common arithmetic operations (addition, substraction, multiplication, division, exponientation, logarithm, maximum, comparison, GCD) over natural numbers (using a decimal representation to make compile-time errors friendlier).

Lennart Augustsson informs us that type-level is used in the llvm binding to

  • keep track statically of vector lengths
  • sure that they are a power of 2
  • making sure that zero and sign extension between integer types go from a smaller to a bigger type
  • making sure that bitcast is done between types of the same number of bits

For a rather stunning example of what you can do with the Haskell LLVM embeddings — something you won’t see anywhere else — check out Lennart Augustsson’s embedding of BASIC in Haskell as a DSL, which also generates very competitive native code via LLVM…

Leave a comment