什么是最简单的函数式编程语言? [英] What is the most minimal functional programming language?

查看:136
本文介绍了什么是最简单的函数式编程语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最简单的函数式编程语言是什么?

解决方案

这取决于你的意思。

首先,函数式语言的祖先首先是数学逻辑。事实上,某些逻辑的计算使用来了。从某种意义上说,许多数学系统(其核心通常非常小)可以称为功能语言。但我怀疑这就是你所追求的!



最有名的是 Alonzo Church lambda微积分,其中有变体和后代:




  • 最简单的形式就是所谓的无类型lambda微积分。这只包含lambda抽象,没有限制它们的使用。仅使用匿名函数创建数据结构是通过所谓的教会编码完成的,并通过其基本操作来表示数据;数字5变成了重复5次等等。


  • Lisp-family语言比没有类型的lambda微积分稍微多一点,利弊细胞,以及其他一些事情。我怀疑Scheme在这里是最简约的,就好像内存服务于我,它最初是作为教学语言创建的。

  • lambda演算的最初目的,当描述逻辑证明的时候失败了,当无类型的形式被证明是不一致的,这是一种礼貌用语,让你证明虚假是真实的。 (历史琐事:证明这一点的论文,当时是一件重要的事情,通过写一个合乎逻辑的证明,以计算术语,进入了一个无限循环。)无论如何,通过引入键入的lambda微积分来恢复逻辑。然而,这些对于编程语言来说并不直接有用,特别是因为逻辑上的声音使语言不是图灵完成的。然而,类似于Lisp从无类型的lambda演算衍生而来,一种通过内置递归扩展的类型化的lambda演算,代数数据类型以及其他一些功能可以为您提供扩展的ML语言系列。这些倾向于最低限度
    ,在许多情况下,句法结构可以直接翻译成lambda表达式。除了明显的ML方言外,这里还包括Haskell和其他一些语言。然而,我不知道任何特别简约的类型化函数式语言,这样的语言可能会遭受差的可用性远远低于最低限度的非类型化语言。



变种去了,没有额外功能的纯粹的无类型lambda微积分是图灵完成的,并且大概尽可能少!

然而,可以说更少的是消除这个概念完全是变量 - 事实上,这最初是为了简化关于逻辑系统的元数学证明(如果内存服务于我),并且仅使用称为 combinators 的高阶函数。这里我们有:

$ ul
  • 组合逻辑本身,最初由 MosesSchönfinkel并通过哈斯克尔咖喱进行广泛开发。每个组合子由一个简单的替换规则定义,例如 Sxyz = xz(yz)。在这个定义中小写字母的使用方式与变量类似,但请记住,组合逻辑本身不使用变量,或者根本不指定名称。可以肯定,组合逻辑是最小的,但不像编程语言那么友好。最着名的是 SK 组合子库。 S的定义如上例所示; K是 Kxy = x 。单独这两个组合器就足以使它完成图灵。这几乎是极其微小的。

  • Unlambda 是一种基于SK组合器的语言,它扩展了一些额外的特殊属性的组合器。尽管最小化了,但是可以让你编写Hello World。


  • 尽管两个combinator比你需要的多。存在各种单组合碱基;也许最为人所知的是 iota Combinator ,定义为 x = xSK ,它用于一种极简主义语言,也称为 Iota

  • 还有一些注释是 Lazy K ,它与Unlambda不同,它没有引入额外的组合器,没有边效果,并使用懒惰评估。基本上,它是基于combinator的深奥语言世界的Haskell。它支持SK基础以及iota combinator。 可能是品味的问题。


    What is the most minimal functional programming language?

    解决方案

    It depends on what you mean by minimal.

    To start with, the ancestor of functional languages is, first and foremost, mathematical logic. The computational use of certain logics came after the fact. In a sense, many mathematical systems (the cores of which are usually quite minimal) could be called functional languages. But I doubt that's what you're after!

    Best known is Alonzo Church's lambda calculus, of which there are variants and descendants:

    • The simplest form is what's called the untyped lambda calculus; this contains nothing but lambda abstractions, with no restrictions on their use. The creation of data structures using only anonymous functions is done with what's called Church encoding and represents data by fundamental operations on it; the number 5 becomes "repeat something 5 times", and so on.

    • Lisp-family languages are little more than untyped lambda calculus, augmented with atomic values, cons cells, and a handful of other things. I'd suspect Scheme is the most minimalist here, as if memory serves me it was created first as a teaching language.

    • The original purpose of the lambda calculus, that of describing logical proofs, failed when the untyped form was shown to be inconsistent, which is a polite term for "lets you prove that false is true". (Historical trivia: the paper proving this, which was a significant thing at the time, did so by writing a logical proof that, in computational terms, went into an infinite loop.) Anyway, the use as a logic was recovered by introducing typed lambda calculus. These tend not to be directly useful as programming languages, however, particularly since being logically sound makes the language not Turing-complete.

    • However, similarly to how Lisps derive from untyped lambda calculus, a typed lambda calculus extended with built-in recursion, algebraic data types, and a few other things gets you the extended ML-family of languages. These tend to be pretty minimal at heart, with syntactic constructs having straightforward translations to lambda terms in many cases. Besides the obvious ML dialects, this also includes Haskell and a few other languages. I'm not aware of any especially minimalist typed functional languages, however; such a language would likely suffer from poor usability far worse than a minimalist untyped language.

    So as far as lambda calculus variants go, the pure untyped lambda calculus with no extra features is Turing-complete and about as minimal as you can get!

    However, arguably more minimal is to eliminate the concept of "variables" entirely--in fact, this was originally done to simplify meta-mathematical proofs about logical systems, if memory serves me--and use only higher-order functions called combinators. Here we have:

    • Combinatory logic itself, as originally invented by Moses Schönfinkel and developed extensively by Haskell Curry. Each combinator is defined by a simple substitution rule, for instance Sxyz = xz(yz). The lowercase letters are used like variables in this definition, but keep in mind that combinatory logic itself doesn't use variables, or assign names to anything at all. Combinatory logic is minimal, to be sure, but not too friendly as a programming language. Best-known is the SK combinator base. S is defined as in the example above; K is Kxy = x. Those two combinators alone suffice to make it Turing-complete! This is almost frighteningly minimal.

    • Unlambda is a language based on SK combinators, extending it with a few extra combinators with special properties. Less minimal, but lets you write "Hello World".

    • Even two combinators is more than you need, though. Various one-combinator bases exist; perhaps the best known is the iota Combinator, defined as ιx = xSK, which is used in a minimalist language also called Iota

    • Also of some note is Lazy K, which is distinguished from Unlambda by not introducing additional combinators, having no side effects, and using lazy evaluation. Basically, it's the Haskell of the combinator-based-esoteric-language world. It supports both the SK base, as well as the iota combinator.

    Which of those strikes you as most "minimal" is probably a matter of taste.

    这篇关于什么是最简单的函数式编程语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆