“const id”的行为 [英] the behavior of "const id"
问题描述
myLast 我正在处理99个Haskell问题,并且看到了一个用于查找列表的最后一个元素的解决方案。 = foldr1(const id)
const $ c $的类型c>是
a - > b - > a
,但是 const id
的
那么这里有什么魔力?
code> id 是 c-> c
;它只是返回它给出的相同的东西。
a - > B->一种
。在 const id
中, a
变成 c-> c
,所以在这种情况下const的类型变成:
pre code>(c-> c) - > b - > (c-> c)
现在你已经应用了这个const函数, code> id 就可以了,那么你只剩下 b - > (c-> c)
。
: const const id
是 a-> b-> a
,以及 const const const id $ c的类型$ c>是
b-> a-> a
,依此类推!
I'm working on the 99 Haskell questions and saw a solution for finding the last element of a list:
myLast = foldr1 (const id)
the type of const
is a -> b -> a
but that of const id
is b -> a -> a
so what's the magic here?
The type of id
is c->c
; it just returns the same thing it is given.
The type of const
is a->b->a
. In const id
, a
becomes c->c
, so the type of const in this case becomes:
(c->c) -> b -> (c->c)
Now that you have applied this const function, i.e. you have passed id
to it, then you are left with b -> (c->c)
.
PS: The type of const const id
is a->b->a
, and the type of const const const id
is b->a->a
, and so on!
这篇关于“const id”的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!