compiler-constructionfunctional-programmingtranspiler

Is this statement about functional programming languages correct?


I was reading a book on Compiler Design and there's a part in it which says,

The main difference in the compilers of different languages is concerned with the code generated by them. In general, it can be said that the compilers for imperative and object oriented languages generate the code in assembly language; whereas functional language compilers generate in C or C++.

Is the last part about C/C++ correct? I couldn't find anything through a Google search so I am asking here.


Solution

  • Is the last part about C/C++ correct?

    No, it's not.

    Some languages do compile to C, but that's not specific to functional languages. If this is more common among functional languages than non-functional ones, it certainly isn't so to the extent that one might call this a property of functional languages.

    Further it's definitely not the case that most real-world functional programming languages are compiled to C (by their official and/or most used implementation). If I list the first ten functional programming languages/implementations I can think of (Haskell (GHC, Hugs), OCaml, F#, Scala, Clojure, Racket, Common Lisp (SBCL, CLisp)), none of them compile to C (to the best of my knowledge). GHC did have a C backend at one point, but that's been discontinued.

    Two languages, that I can think of, whose primary implementations compile to C are Vala and Haxe, neither of which are functional languages. In one of the linked threads, Chicken Scheme was mentioned. So that's one relatively well-known implementation that uses C. That's hardly enough to justify the claim that this is "generally" the case.