Is Haskell a Lisp?
I've been reading The Haskell R开发者_高级运维oad to Logic, Maths and Programming by Doets and Eijck 2004. It seems to be a well respected book, but I was struck when it claims that Haskell is a member of the Lisp family. Is this accurate? I would characterise Lisps with s-expressions, impure functions, and lists as the only composite data structure. Haskell has none of that. What justification is there for that claim?
Lisp is a very vague concept. I see two more or less useful interpretations:
Lisp as a family of languages which share some common ideas. In a wide interpretation very different languages belong to this family: Common Lisp, Scheme, Logo, Dylan, Emacs Lisp, Clojure, RLisp, 3Lisp and many, many others.
Lisp as a lineage of languages that are somehow implementing a core language (CAR, CDR, CONS, LAMBDA, PROG, SET, SETQ, QUOTE, DEFUN, IF, COND, DO, ...): Lisp 1.5, MacLisp, Lisp Machine Lisp, Emacs Lisp, Common Lisp, ISLisp. Note that these languages usually have 'Lisp' as part of their name.
Some typical things we find in Lisp dialects: strict evaluation, side effects, direct imperative programming, functional programming constructs, s-expressions, evaluation, macros.
Haskell is a very different language: non-strict evaluation, syntax not based on top of s-expressions, static typing, purely functional.
Haskell does not fit 1 nor 2. So, I would say Haskell is not a Lisp.
Similar we can say that a Functional Programming language is:
a language that supports Functional Programming: Lisp, APL, ..., ML, SML, OCAML, F#, Miranda, Haskell, ...
a language that enforces Functional Programming. Here Lisp already does not really fit in, since imperative or even object-oriented programming is not second class in Lisp.
a language that enforces Pure Functional Programming. Here we have Haskell as a good example. As a relatively new Lisp dialect Clojure also might fit in.
Usually Lisp does only support, but not enforce Functional Programming. So it is a Functional Programming Language in a wider interpretation.
Haskell is one of the languages that is seen as a Purely Functional Programming Language.
I think that it is a stretch to consider Haskell as a member of the LISP family, but I suspect the reasoning goes something like this...
When classifying programming languages, it is meaningful to divide them into two groups: those descended from FORTRAN and those that are not. In 1958, the "not FORTRAN group" pretty much meant LISP (at least, among the languages that are not extinct today). So, for a time, the programming language family tree had two main branches: the FORTRAN descendants and the LISP descendants. If those are the only two choices, then I would put Haskell into the LISP branch.
However, many commentators consider languages like ML, Prolog and APL to have arisen "out of the blue" -- introducing sufficiently distinct paradigms to merit lineages unto themselves. Haskell is clearly kin to ML.
As examples of such classifications, see the following programming language family trees:
O'Reilly's Programming Language Poster
Computer Languages Timeline at levenez.com
HOPL: an interactive Roster of Programming Languages (Haskell Entry)
I would not agree with that. They're both functional programming languages and Lisp influenced Haskell, but Haskell is not a Lisp derivative. Just look at the amount of parenthesis and you can tell.
I think Haskell is a Lisp in the sense that they're both based on the λ calculus. Haskell is an implementation of λ.
Though most people would say that Haskell belongs to the ML family. ML is also based on λ, as are all functional languages I know of.
Under the hood, OCam (descended from ML) is compiled to combinatory logic, a formalism that is equivalent to λ calculus, and was invented by Haskell Curry, the logician whom Haskell is named after. But the use of combinatory logic for functional langauge compilation seems to be less popular nowadays, so I'm not sure about modern compilers like GHC.
Lisp's syntax is almost identical with λ calculus, which makes this family (Scheme, Clojure, etc) very special.
What people define as a lisp varies. The original specification for a lisp didn't mention macros at all and only defined a small list of primitive function, which, if my memory serves me, are the following:
cons
car
cdr
cond
eq
atom
and
or
not
nil
This might not be the full list, or it might have few additional members, but in any case, John McCarthy's original specification was very small.
If you define a lisp as any language that defines all of those functions, then most modern languages are lisps, including haskell.
A more strict and modern definition of a lisp is as follows:
- eager evaluation
- dynamic typing
- impure functional
- macros
- focus on lists as primary data structure
Haskell doesn't fit the first 3, it's macros (template haskell) don't follow the code-is-data paradigm, and while lists are very important, they're not the primary data structure.
So I would say no, Haskell is not a lisp.
Haskell is not lisp of course. Everyone has his own understanding what the heck "lisp" is. IMHO lisp is a language where the source code is a valid structure in that same language. Haskell source code is not a valid structure in haskell, hence they have to have a separate syntax (Haskell Template) to manipulate their own source code.
But there's at least one interesting feature in haskell that reminds me of lisp. Its the syntax of function calls: func args1 agr2 arg3. Lisp has EXACTLY the same syntax: (func args1 agr2 arg3). In fact you can include outside parens in haskell too. All other algol family languages introduce parens and commas between function name and arguments.
I'd say that both are functional languages, which makes them belong to the same family. However, I wouldn't call Haskell a Lisp derivative (like Scheme).
Arguably, all functional languages are descendants of Scheme to the extent that Scheme stumbled into, roughly, implementing the lambda calculus (though with quirks), and functional languages also implement the lambda calculus, though they don't necessarily always look like it. Also, arguably, the ML lineage is completely distinct because it goes back to Landin's ISWIM, which was influential but never implemented, had very little to do with Lisp, and from the start knew its theoretical foundations.
The real thing though is that Haskell and Lisp have much more in common with one another than either has with either the C family or the Prolog family.
I would have argued that folks should look past syntactic issues, but I forgot that Lispers define syntax as a key part of what it means to be a lisp. Which I think is goofy because then arguably Haskell isn't a Lisp, but Liskell is, even though the latter is basically a processor for the former.
Hoyte compares some languages and claims that Haskell is NOT a Lisp for it is too strict in types and only for academics, whereas Common Lisp is more like a prototyping language (no strictness, dynamic typing).
See: Let Over Lambda—50 Years of Lisp by Doug Hoyte (an advanced book about Common Lisp, http://letoverlambda.com/)
Haskell and Common Lisp (probably all Lisps) are optimized against the functional programming (FP) paradigm. Haskell is pure, whereas Common Lisp is unpure. Contrast the term FP also with "total functional programming".
Also have a look at this diagram comparing programming language paradigms: http://www.info.ucl.ac.be/~pvr/paradigms.html
精彩评论