Haskell有变量吗? [英] Does Haskell have variables?
问题描述
我经常听到Haskell没有变量的说法;特别是,这个答案声称它不会'吨,它被提高了至少9倍,并被接受。
那么它是否有变量,为什么?
这个问题似乎也适用于ML,F#,OCaml,Erlang,Oz,Lava以及所有 SSA 中间语言。
Haskell默认具有不可变变量(数学意义上的变量):
foo xy = x + y * 2
默认情况下变量不是可变单元格。
Haskell虽然也有可变单元格,但是您可以明确地启用它们:
> v< - newIORef 0
> readIORef v
0
> writeIORef v 7
> readIORef v
7
所以, YES Haskell具有真实变量。但默认情况下,它不会使用可变变量。
I've frequently heard claims that Haskell doesn't have variables; in particular, this answer claims that it doesn't, and it was upvoted at least nine times and accepted.
So does it have variables or not, and why?
This question also appears to apply ML, F#, OCaml, Erlang, Oz, Lava, and all SSA intermediate languages.
Haskell has immutable variables (variables in the math sense) by default:
foo x y = x + y * 2
By default variables are not mutable cells.
Haskell also has mutable cells though, but you enable them explicitly:
> v <- newIORef 0
> readIORef v
0
> writeIORef v 7
> readIORef v
7
So, YES Haskell has true variables. But it does not use mutable variables by default.
这篇关于Haskell有变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!