Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When choosing a functional programming language for use with LLVM, what are the trade-offs?

Let's assume for the moment that C++ is not a functional programming language. If you want to write a compiler using LLVM for the back-end, and you want to use a functional programming language and its bindings to LLVM to do your work, you have two choices as far as I know: Objective Caml and Haskell. If there are others, then I'd like to know about those too.

I'm not asking for subjective opinions, so please don't give this the subjective tag. I want to make up my own mind about this, but I'm not sure I know what are all the trade-offs. So, StackOverflow to the rescue. What are the trade-offs?

like image 584
james woodyatt Avatar asked Nov 20 '09 23:11

james woodyatt


People also ask

What is functional programming used for?

Functional programming seeks to take advantage of language support in using functions as variables, arguments, and return values to create elegant code. Because first class functions are so flexible and useful, even strongly OOP languages like Java and C# have moved to incorporate first class function support.

Does OCaml use LLVM?

OCaml is the only functional language with bindings in the LLVM distro itself and documentation on llvm.org such as the Kaleidoscope tutorial. If you have OCaml installed when you build and install LLVM then it will automatically build and install the LLVM bindings for OCaml as well.

What is Haskell in functional programming language?

Haskell (/ˈhæskəl/) is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation.

Is LLVM open source?

LLVM is publicly available under an open source License. Also, you might want to check out the new features in Git that will appear in the next LLVM release. If you want them early, download LLVM through anonymous Git.


1 Answers

Either OCaml or Haskell would be a good choice. Why not check out the LLVM tutorials for each language? The LLVM tutorial for OCaml is here: http://llvm.org/docs/tutorial/OCamlLangImpl1.html

Haskell has more momentum these days, but there are plenty of good parsing libraries for OCaml as well including the PEG parser generator Aurochs, Menhir, and the GLR parser generator Dypgen. Also check out this presentation on pcl a monadic parser combinator library for OCaml (like Parsec for Haskell) there's some good info in there comparing Haskell's and OCaml's approach: http://osp.janestreet.com/files/pcl.pdf

Some will say that laziness gives Haskell the edge in parsing, but you can get laziness in OCaml as well.

like image 73
aneccodeal Avatar answered Sep 20 '22 18:09

aneccodeal