p*****2 发帖数: 21240 | 1 前几天刚学Scala的时候感觉如果code里边都用immutable的变量就是FP了,被人嘲笑了
。这两天接触的更多了,感觉这个没错呀。如果能做到不用mutable变量,想不
functional都难吧? |
E*****m 发帖数: 25615 | 2 你這個不正統的說法,其實在實踐上也沒錯。
不過有些 impure FP 事實上也用 mutable data, 所以你事實上
是在說 purity 的觀念。
FP 還有其他的內涵,比方說 Higher Order Function 之類的,
那就不是只用 immutable 就行了。 |
p*****2 发帖数: 21240 | 3
这两天搞明白了,即使impure FP也鼓励使用pure FP的style去写code, 因此尽量写
pure FP的code
另外,我个人感觉HOF是避免mutable的关键,因为需要mutable变量的操作给封装起来
了。
【在 E*****m 的大作中提到】 : 你這個不正統的說法,其實在實踐上也沒錯。 : 不過有些 impure FP 事實上也用 mutable data, 所以你事實上 : 是在說 purity 的觀念。 : FP 還有其他的內涵,比方說 Higher Order Function 之類的, : 那就不是只用 immutable 就行了。
|
r*******n 发帖数: 3020 | 4 我觉得data immutable是FP特性的基础,没有它,Higher Order funciton就实现不了
【在 p*****2 的大作中提到】 : : 这两天搞明白了,即使impure FP也鼓励使用pure FP的style去写code, 因此尽量写 : pure FP的code : 另外,我个人感觉HOF是避免mutable的关键,因为需要mutable变量的操作给封装起来 : 了。
|
p*****2 发帖数: 21240 | 5
有道理。我也感觉mutability是最基础的原则。
【在 r*******n 的大作中提到】 : 我觉得data immutable是FP特性的基础,没有它,Higher Order funciton就实现不了
|
s****0 发帖数: 117 | 6 假定f=x+y+c
如果c不是immutable的,每次调用f(x,y)返回值不确定,那这玩意不是FP.
如果给定了x=b, f(x,y) 必须和g(y)=f(b,y)是一致的。所以在g里能看见f里的所有东
西,并且x是b.
个人理解。 |
l*******b 发帖数: 2586 | 7 我也觉得好像是这样
【在 s****0 的大作中提到】 : 假定f=x+y+c : 如果c不是immutable的,每次调用f(x,y)返回值不确定,那这玩意不是FP. : 如果给定了x=b, f(x,y) 必须和g(y)=f(b,y)是一致的。所以在g里能看见f里的所有东 : 西,并且x是b. : 个人理解。
|
E*****m 发帖数: 25615 | 8 原則上是這樣,但是一個語言做成這樣就是廢物了, 沒辦法
接收 user input, 沒辦法 db access, 沒辦法產生 random number,
連讀出現在時間都不行, 所以要不然就 impure, 要不然就得去
用 monad。
【在 s****0 的大作中提到】 : 假定f=x+y+c : 如果c不是immutable的,每次调用f(x,y)返回值不确定,那这玩意不是FP. : 如果给定了x=b, f(x,y) 必须和g(y)=f(b,y)是一致的。所以在g里能看见f里的所有东 : 西,并且x是b. : 个人理解。
|
k******a 发帖数: 2436 | 9 I am baffled by these discussions. You guys need to spend a few minutes with
Lisp to understand what functional programming is. IO are both considered
immutable values and there is no assignment or concept of variables.
C# only introduced lambda as a language feature, which allows run-time
created function instances, not just compile-time. That makes functions
first class data types.
Did java added lambda? I have no knowledge of it. But without a language
level change you can at most get syntax sugar as approximations, not real
lambda.
【在 E*****m 的大作中提到】 : 原則上是這樣,但是一個語言做成這樣就是廢物了, 沒辦法 : 接收 user input, 沒辦法 db access, 沒辦法產生 random number, : 連讀出現在時間都不行, 所以要不然就 impure, 要不然就得去 : 用 monad。
|
t****a 发帖数: 1212 | 10 我对LISP是不是很干净强的FP最近越来越不确定。
Haskell是公认的FP,现在找本FP算法书都是Haskell的
with
【在 k******a 的大作中提到】 : I am baffled by these discussions. You guys need to spend a few minutes with : Lisp to understand what functional programming is. IO are both considered : immutable values and there is no assignment or concept of variables. : C# only introduced lambda as a language feature, which allows run-time : created function instances, not just compile-time. That makes functions : first class data types. : Did java added lambda? I have no knowledge of it. But without a language : level change you can at most get syntax sugar as approximations, not real : lambda.
|
|
|
l*********s 发帖数: 5409 | 11 what is the application of run-time generated function instances?
with
【在 k******a 的大作中提到】 : I am baffled by these discussions. You guys need to spend a few minutes with : Lisp to understand what functional programming is. IO are both considered : immutable values and there is no assignment or concept of variables. : C# only introduced lambda as a language feature, which allows run-time : created function instances, not just compile-time. That makes functions : first class data types. : Did java added lambda? I have no knowledge of it. But without a language : level change you can at most get syntax sugar as approximations, not real : lambda.
|
p*****2 发帖数: 21240 | 12
FP
【在 l*********s 的大作中提到】 : what is the application of run-time generated function instances? : : with
|
l*********s 发帖数: 5409 | 13 FP == "fang pi" ?
【在 p*****2 的大作中提到】 : : FP
|
E*****m 发帖数: 25615 | 14
with
why IO is immutable? You get same input every time?
Lisp has "setq", which is indeed assignment. There is no such thing
in Haskell, if I got it right.
Actually, LISP is not the purest FP language. You should not use Lisp
as an FP benchmark.
【在 k******a 的大作中提到】 : I am baffled by these discussions. You guys need to spend a few minutes with : Lisp to understand what functional programming is. IO are both considered : immutable values and there is no assignment or concept of variables. : C# only introduced lambda as a language feature, which allows run-time : created function instances, not just compile-time. That makes functions : first class data types. : Did java added lambda? I have no knowledge of it. But without a language : level change you can at most get syntax sugar as approximations, not real : lambda.
|
E*****m 发帖数: 25615 | 15
這很有用啊! 比方說 sort 需要 comparator, 而 comparator 又由
input data 決定, 你就可以在拿到data 後生成 comparator 給
sort 用。
【在 l*********s 的大作中提到】 : what is the application of run-time generated function instances? : : with
|
l*******b 发帖数: 2586 | 16 这个是所有人工智能程序最基本的要求吧.不然都是给定了的玩具.哪里来的智能
【在 l*********s 的大作中提到】 : what is the application of run-time generated function instances? : : with
|