Functional/non-functional and interpreted/compiled are two different categorizations, yet it seems that there are a lot of overlaps in the programming languages that fall under those categories. Is this a coincidence?
-
5So you are saying Haskell and ML family, eg. the most popular functional languages, are interpreted? – Euphoric Jun 15 '14 at 06:14
-
1They're not. The Lisp family used to be commonly considered interpreted (I still have old books that make the claim) but that's not true now and maybe never really was. However, unlike ML and Haskell, Lisp has dynamic typing. That means a tiny bit of work must be done at run-time (unless the optimizer can eliminate it) to determine which implementations of certain operations to use for particular values based on their types - similar to the tiny "overhead" for late-binding member functions in object-oriented programming. Dynamic typing is really just another form of late binding. – Jun 15 '14 at 07:13
-
Then again, Haskell is statically typed (and definitely compiled) yet has a similar tiny-but-there run-time cost for calling typeclass members - yet another form of late binding, really - and although I don't know much about ML, it probably has some equivalent too. In my mind, late binding is one of those things that shows that interpreting vs. compiling is blurry - though thinking of particular kinds of run-time work as left-over interpreting is probably a bit odd when the whole point of a program is to do work at run-time. – Jun 15 '14 at 07:23
-
@Euphoric no, where do you get that from the question? – Fabio Marcolini Jun 15 '14 at 07:28
-
4You are confusing languages with interpreters/compilers. Many languages have both compilers and interpreters (REPLs) - a language is **not** defined by the execution environment/engine. – Oded Jun 15 '14 at 07:57
-
1@Oded: A REPL ist not the same thing as an interpreter. The Scala REPL is implemented with a compiler, as is Clojure's and GHC's. – Jörg W Mittag Jun 15 '14 at 18:40
-
@JörgWMittag - fair point. Was just saying that there is no such thing as an interpreted language vs a compiled one, given than many languages have both. – Oded Jun 15 '14 at 19:09
-
I think the OP means to compile down to machine code, an executable binary. Not bytecode which requires separate binary to run. – Kris Apr 05 '16 at 10:00
1 Answers
There is no such thing as an "interpreted language". A language is a set of abstract mathematical rules. A language isn't interpreted or compiled, it just is. Interpretation and compilation are traits of, well, the interpreter or compiler (duh!), not the language.
A language is an abstract entity, an interpreter or compiler is a concrete implementation of that abstraction. The two live on completely different levels of abstraction. The term "interpreted language" is not just wrong, it doesn't even make sense. If English were a typed language, "interpreted language" would be a type error!
You can't ask whether a language is an interpreted language, the answer isn't "yes" or "no", because the question itself is non-sensical. It's like asking whether orange is a prime number.
Every language can be implemented with an interpreter, and every language can be implemented with a compiler. You can automatically derive a compiler from an interpreter and an interpreter from a compiler.
The vast majority of languages have both compiled and interpreted implementations. The vast majority of modern high-performance language implementations are mixed-mode implementations which combine interpretation and compilation.
Now, let's look at some popular functional languages and some of their popular implementations:
- Haskell
- GHC, the Glorious Glasgow Haskell Compiler: obviously a compiler
- UHC, the Utrecht Haskell Compiler: again, a compiler
- JHC, also a compiler
- HUGS (no longer maintained): an interpreter
- Standard ML
- SML/NJ (Standard ML of New Jersey): a compiler
- MLton: a compiler
- ML Kit: a compiler
- Moscow ML: a compiler
- TILT: a compiler
- SML.NET: a compiler
- Alice: an interpreter
- OCaml: there is only one implementation of OCaml, a compiler
- F♯: there is only one implementation of F♯ (Microsoft Visual F♯), a compiler
- Scala: there is only one implementation of Scala, a compiler
- Clojure
- Clojure: a compiler for the Java platform
- ClojureCLR: a compiler for the CLI platform
- ClojureScript: a compiler for the ECMAScript platform
- Scheme
- Racket: compiles Scheme to bytecode, then either interprets or compiles that byte code
- Stalin: a compiler
- Gambit: a compiler
- CHICKEN: a compiler
- Ikarus: a compiler
- Larceny: a compiler
- IronScheme: a compiler
- Bigloo: a compiler
- Kawa: an interpreter
- Gauche: an interpreter

- 101,921
- 24
- 218
- 318
-
"The vast majority of modern high-performance language implementations are mixed-mode implementations which combine interpretation and compilation." I would highly disagree. JIT is not interpretation. – Euphoric Jun 15 '14 at 12:25
-
-
OCaml has something like two implementations in one: a normal compiler and a bytecode compiler. The first is a normal optimizing compiler while the second is more a mixed-mode system with a bytecode interpreter. They're shipped together, but are separate backends. – Tikhon Jelvis Jun 18 '14 at 16:29
-
@TikhonJelvis: I assume the latter one is used for staged compilation / compile time metaprogramming à la `camlp4`? BTW: "mixed-mode" refers to combining an interpreter and a compiler, but from what you describe, there is a pure byte code interpreter, no compiler, so "mixed-mode" doesn't really apply. – Jörg W Mittag Jun 18 '14 at 16:35
-
@JörgWMittag: Well, you have to compile to the bytecode first. Perhaps I misunderstood what you meant by mixed-mode though. The bytecode compiler *is* used by `camlp4`, but that's a bit of a historical accident and makes it slow, so they're not using it for their new "extension point" system. Mostly, the bytecode compiler is useful for portability and simplicity: for example, it's used by `js_of_ocaml` to compile to JavaScript. I think it's also used for the REPL. – Tikhon Jelvis Jun 18 '14 at 16:42
-
@TikhonJelvis: "mixed-mode" means that the same program written in the same language is both interpreted and compiled. E.g. HotSpot is mixed-mode, because it both interprets and compiles JVM byte code. In fact, during the same run of the same program, the same part of the program may at different times be either interpreted or compiled. In your case, the OCaml byte code interpreter only interprets OCaml byte code, it never compiles it. And the OCaml compiler only compiles OCaml, it never interprets it. Those are two separate stages. – Jörg W Mittag Jun 18 '14 at 16:46
-
-
*Technically* any language can be either compiled or interpreted, but many languages have a primary implementation that is one or the other, or have their most common few implementations be one or the other, so, for example, it's not really that unreasonable to say that C is a compiled language or Python is an interpreted language. It's sufficiently true in most cases to the extent that anyone cares. – zstewart Dec 01 '16 at 20:36
-
@TikhonJelvis: No. It is JIT *and* interpretation *of the same language*. E.g. V8 is a pure compiler. It never interprets. It is single-mode, even though it has a JIT. CPython has both a compiler and an interpreter, but they don't mix: *first* the compiler compiles Python to CPython bytecode, *then* the interpreter interprets CPython bytecode. The don't process the same language, and they don't run at the same time. – Jörg W Mittag Dec 02 '16 at 00:23
-
@zstewart: Why is it reasonable to say that Python is an interpreted language? All currently existing Python implementations have a compiler. Some even have more than one (e.g. PyPy, Pyston). No currently existing Python implementation interprets Python. There are more C interpreters (2) than there are Python interpreters (0), so why is C compiled language and Python not? And if I compile C to x86 machine code and then run that machine code in an x86 interpreter, is C then compiled or interpreted? And why is Java a compiled language, when the typical execution mode is identical to Python's? – Jörg W Mittag Dec 02 '16 at 00:27
-
@JörgWMittag First we should probably define what is meant by compiler or interpreter. The definition I would go with is that an interpreter is a program that, given some code, executes the program that that code describes, whereas a compiler, given some code, transforms and gives as output code in a different format which describes the same program. An interpreter may contain a compiler as an implementation detail, and the output of a compiler always needs an interpreter to execute it (even a CPU is just a hardware interpreter, for machine code). Does that definition seem reasonable to you? – zstewart Dec 02 '16 at 15:07
-
@zstewart: [Yes, it does.](http://softwareengineering.stackexchange.com/a/269878/1352) – Jörg W Mittag Dec 04 '16 at 08:43