C ++ 0x(C ++ 11)作为函数语言? [英] C++0x (C++11) as functional language?

查看:141
本文介绍了C ++ 0x(C ++ 11)作为函数语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道C ++ 0x(C ++ 11)(lambdas和完美转发)是否是一个函数式语言的超集。

解决方案

函数式编程范式模型计算作为集合之间的关系,并且因此是固有地声明性的。然而,在实践中,我们经常认为函数是命令式的,即你放入一个输入值并得到一个输出值,与一个过程一样。从这个角度来看,函数的特性是没有副作用。由于术语的不确定性,我们称之为这样的函数 pure ,并且只有纯函数的语言将是纯粹功能的语言。



但是,并非所有的函数式语言都是纯粹的:功能性语言是一种具有语法和语义的语言,它允许程序员有效地使用函数式范式。使用范例可行的一些概念包括其中包括词法闭包,高阶函数,变体类型和模式匹配,惰性求值,类型推断(在静态类型语言的情况下)的lambda表达式。 p>

这不是一个授权的列表,一个语言可以很好地运行,而不提供所有或甚至大多数,但如果一种语言 - 即使它们可用不得不跳过主要的圈子 - 他们的存在是一个强有力的指示,语言应该被视为功能。



我不知道足够关于Boost来决定是否C ++ 03 + Boost是一个可行的函数语言,但C ++ 0x肯定使C ++更具功能,甚至可能推动它超越函数式语言领域的主观边界。



另外,同样的注意事项也适用于其他编程范例:C ++也不是一种纯面向对象的语言(事实上,设计一种语言是非常困难的 - 甚至在理论上是不可能的 - 纯粹的功能和纯粹的面向对象),大多数特征通常与OO语言(类,继承,封装)关联实际上不是授权的...


i'm wondering if C++0x (C++11) (with lambdas and perfect forwarding) is (a superset of) a functional language. is there any feature of functional languages, that C++ doesn't have?

解决方案

The functional programming paradigm models computation as a relation between sets, and is thus inherently declarative. However, in practice, we often think of functions as imperative, ie you put in an input value and get out an output value, same as with a procedure. From this point of view, the characteristic property of a function is that it has no side-effects. Because of ambiguity of the terms, we call such a function pure, and a language which only has pure functions would be a purely functional language.

However, not all functional languages are pure: A functional language is a language with syntax and semantics which allows the programmer to use the functional paradigm efficiently. Some of the concepts which make using the paradigm feasible include - among others - lambda expressions with lexical closure, higher-order functions, variant types and pattern matching, lazy evaluation, type-inference (in case of statically-typed languages).

This is by no means an authorative list, and a language can very well be functional without providing all or even most of them, but if a language does - ie makes them usable without having to jump through major hoops - their presence is a strong indicator that the language should be considered functional.

I don't know enough about Boost to decide whether or not C++03 + Boost is a viable functional language, but C++0x definitely makes C++ more functional, perhaps even pushing it over the subjective boundary of the realm of functional languages.

As an aside, the same considerations apply to other programming paradigms: C++ is also not a purely object-oriented language (indeed, it's very hard - perhaps even theoretically impossible - to design a language which is both purely functional and purely object-oriented), and most features one commonly associates with OO-languages (classes, inheritance, encapsulation) are actually in no way authorative as well...

这篇关于C ++ 0x(C ++ 11)作为函数语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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