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

问题描述

Haskell 被称为纯函数式语言".

Haskell has been called a "pure functional language."

在这种情况下,纯"是什么意思?这对程序员有什么影响?

What does "pure" mean in this context? What consequences does this have for a programmer?

推荐答案

函数式语言中,你不能做任何有副作用的事情.

In a pure functional language, you can't do anything that has a side effect.

副作用意味着评估一个表达式会改变一些内部状态,这将导致评估相同的表达式有不同的结果.在纯函数式语言中,您可以使用相同的参数根据需要多次计算相同的表达式,并且它始终会返回相同的值,因为没有要更改的状态.

A side effect would mean that evaluating an expression changes some internal state that would later cause evaluating the same expression to have a different result. In a pure functional language you can evaluate the same expression as often as you want with the same arguments, and it would always return the same value, because there is no state to change.

例如,纯函数式语言不能有赋值运算符或进行输入/输出,尽管出于实际目的,即使是纯函数式语言也经常调用不纯的库来进行 I/O.

For example, a pure functional language cannot have an assignment operator or do input/output, although for practical purposes, even pure functional languages often call impure libraries to do I/O.

这篇关于“纯"是什么意思“纯函数式语言"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:47