Haskell 是 Lisp 语言吗?
我一直在读 Doets 和 Eijck 2004 年写的《The Haskell Road to Logic, Maths andProgramming》。这似乎是一本很受人尊敬的书,但当它声称 Haskell 是 Lisp 家族的成员时,我感到很震惊。这准确吗?我将 Lisps 的特征描述为 s 表达式、不纯函数和列表作为唯一的复合数据结构。哈斯克尔没有这些。这种说法有何依据?
I've been reading The Haskell Road 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
Lisp是一个非常模糊的概念。我看到两种或多或少有用的解释:
Lisp 作为一个具有一些共同想法的语言家族。从广泛的解释来看,非常不同的语言都属于这个家族:Common Lisp、Scheme、Logo、Dylan、Emacs Lisp、Clojure、RLisp、3Lisp 等等。
Lisp 作为以某种方式实现核心语言的语言谱系(CAR、CDR、CONS、LAMBDA、PROG、SET、SETQ、QUOTE、DEFUN、IF、COND、DO...):Lisp 1.5、MacLisp 、Lisp Machine Lisp、Emacs Lisp、Common Lisp、ISLisp。请注意,这些语言通常将“Lisp”作为其名称的一部分。
我们在 Lisp 方言中发现了一些典型的东西:严格求值、副作用、直接命令式编程、函数式编程结构、s 表达式、求值、宏。
Haskell 是一种非常不同的语言:非严格求值、不基于 s 表达式的语法、静态类型、纯函数式。
Haskell 不适合 1 或 2。所以,我想说 Haskell 不是 Lisp。
类似地,我们可以说函数式编程语言是:
支持函数式编程的语言:Lisp、APL、...、ML、SML、OCAML、F#、Miranda、Haskell、...
一种强制执行函数式编程的语言。这里 Lisp 已经不太适合了,因为命令式编程甚至面向对象编程在 Lisp 中都不是二流的。
一种强制执行纯函数式编程的语言。这里我们以 Haskell 作为一个很好的例子。作为一种相对较新的 Lisp 方言,Clojure 也可能适合一种
通常 Lisp 只支持,但不强制执行函数式编程。所以它是一种更广泛解释的函数式编程语言。
Haskell 是被视为纯函数式编程语言的语言之一。
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.
我认为将 Haskell 视为 LISP 家族的一员有些牵强,但我怀疑其推理是这样的……
在对编程语言进行分类时,将它们分为两类是有意义的:源自 FORTRAN 的语言和源自 FORTRAN 的语言那些不是的。 1958 年,“非 FORTRAN 族”几乎指的是 LISP(至少在今天尚未灭绝的语言中)。因此,一度,编程语言家谱有两个主要分支:FORTRAN 后代和 LISP 后代。如果这是唯一的两个选择,那么我会将 Haskell 放入 LISP 分支。
然而,许多评论家认为像 ML、Prolog 和 APL 这样的语言是“突然”出现的——引入了足够独特的范式以赋予它们自己的血统。 Haskell 显然与 ML 很相似。
作为此类分类的示例,请参阅以下编程语言族谱:
O'Reilly 的编程语言海报
levenez.com 上的计算机语言时间表
HOPL:交互式编程语言名册(Haskell 条目)
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)
我不同意这一点。它们都是函数式编程语言,Lisp 影响了 Haskell,但 Haskell 并不是 Lisp 的衍生品。只要看看括号的数量就可以知道。
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.
我认为 Haskell 是一种 Lisp,因为它们都基于 λ 演算。 Haskell 是 λ 的一个实现。
尽管大多数人会说 Haskell 属于 ML 家族。 ML 也基于 λ,我所知道的所有函数式语言也是如此。
在底层,OCam(源自 ML)被编译为组合逻辑,这是一种相当于 λ 演算的形式主义,由逻辑学家 Haskell Curry 发明,Haskell 就是以他的名字命名的。但是使用组合逻辑进行函数式语言编译现在似乎不太流行,所以我不确定像 GHC 这样的现代编译器。
Lisp 的语法几乎与 λ 演算相同,这使得这个家族(Scheme、Clojure 等)非常特别。
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.
人们对 lisp 的定义各不相同。 Lisp 的原始规范根本没有提到宏,只定义了一小部分原始函数,如果我没记错的话,如下:
cons
car
cdr
cond
eq
atom
和
或
nil
这可能不是完整列表,或者可能只有很少的其他成员,但无论如何,John McCarthy 的原始规范非常小。
如果您将 lisp 定义为定义所有这些函数的任何语言,那么大多数现代语言都是 lisp,包括 haskell。
lisp 的更严格和现代的定义如下:
Haskell 不适合前 3 个,它的宏(模板 haskell)不遵循代码 -is -数据范例,虽然列表非常重要,但它们不是主要的数据结构。
所以我想说不,Haskell 不是一个口齿不清的人。
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:
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 当然不是 lisp。每个人都有自己对“lisp”到底是什么的理解。
恕我直言,lisp 是一种源代码是该语言的有效结构的语言。
Haskell 源代码不是 Haskell 中的有效结构,因此它们必须有单独的语法(Haskell 模板)来操作自己的源代码。
但 haskell 中至少有一个有趣的功能让我想起了 lisp。它的函数调用语法是:func args1 agr2 arg3。 Lisp 具有完全相同的语法:(func args1 agr2 arg3)。事实上,你也可以在 haskell 中包含外部括号。所有其他 algol 系列语言在函数名称和参数之间引入括号和逗号。
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.
我想说,两者都是函数式语言,这使得它们属于同一个家族。然而,我不会称 Haskell 为 Lisp 的衍生品(如Scheme)。
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).
可以说,所有函数式语言都是Scheme的后代,因为Scheme粗略地陷入了实现lambda演算(尽管有一些怪癖),并且函数式语言也实现了lambda演算,尽管它们不一定总是看起来像它。此外,可以说,ML 谱系是完全不同的,因为它可以追溯到 Landin 的 ISWIM,它很有影响力但从未实现,与 Lisp 关系不大,并且从一开始就知道它的理论基础。
但真正的事情是,Haskell 和 Lisp 之间的共同点比它们与 C 家族或 Prolog 家族的共同点要多得多。
我认为人们应该忽略语法问题,但我忘记了 Lispers 将语法定义为 Lisp 的关键部分。我认为这是愚蠢的,因为可以说 Haskell 不是 Lisp,但 Liskell 是,尽管后者是基本上是前者的处理器。
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 比较了一些语言,并声称 Haskell 不是 Lisp,因为它在类型上过于严格并且仅适用于学术,而 Common Lisp 更像是一种原型语言(没有严格性,动态类型)。
请参阅:Doug Hoyte 的《Let Over Lambda — 50 Years of Lisp》(一本关于 Common Lisp 的高级书籍,http://letoverlambda.com/< /a>)
Haskell 和 Common Lisp(可能所有 Lisp)都针对函数式编程 (FP) 范式进行了优化。 Haskell 是纯粹的,而 Common Lisp 是不纯粹的。将术语 FP 与“全函数式编程”进行对比。
另请看一下比较编程语言范例的图表:http://www. info.ucl.ac.be/~pvr/paradigms.html
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