scala不是函数式语言,与Ocaml的对比

http://blog.enfranchisedmind.com/posts/scala-not-functional/
这篇文章,好像以前记录过,Manads are elepants的作者还写过 blog争论

看看里面一些比较:
1)柯里化和偏应用函数, scala里

[scala toolbar=”false” light=”true”]
def x(a:Int, b:Int) = a + b

def y = x(1) // 不能直接这样,而需要额外声明一下

def y = Function.curried(x _)(1) //2.8已经不鼓励这样用,而用: y = x(_:Int, 1)
[/scala]

2)代数数据类型(ADT)
Ocaml里:

[scala toolbar=”false” light=”true”]
type robert = Foo of int | Bar of string | Baz;;
[/scala]

Scala里:

[scala toolbar=”false” light=”true”]

sealed abstract class Robert;
sealed case class Foo(value:Int) extends Robert;
sealed case class Bar(value:String) extends Robert;
sealed case class Baz extends Robert;
[/scala]

james的回复:
http://james-iry.blogspot.com/2009/05/erlang-is-not-functional.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注