这个haskell表达式是如何评估的 [英] how is this haskell expression evaluated
问题描述
(flip const 1。const flip 3 const 4)5
最终结果是5,但我不知道它是如何评估的。
通过定义 通过定义 定义 通过定义 通过定义 / code>:
。
$ b $ pre $ flip const 1 $((const flip 3)const 4)5
const
:
= flip const 1 $ flip const 4 5
flip :
= flip const 1 $ const 5 4
const
:
=翻转常量1 5
flip
:
= const 5 1
(作为一点奖金洞察力,你能发现为什么 flip const y
只是 id
对于所有 y
?这将您的表情降低到
(id。id)5
。)
I am learning haskell
and I came across this expression which I could not understand.
(flip const 1 . const flip 3 const 4) 5
The final result is 5 but I have no idea how it is evaluated.
By definition of (.)
:
flip const 1 $ ((const flip 3) const 4) 5
By definition of const
:
= flip const 1 $ flip const 4 5
By definition of flip
:
= flip const 1 $ const 5 4
By definition of const
:
= flip const 1 5
By definition of flip
:
= const 5 1
Which is 5
.
(As a little bonus insight, can you find out why flip const y
is just id
for all y
? This reduces your expression to (id . id) 5
.)
这篇关于这个haskell表达式是如何评估的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!