比较Haskell中的列表 [英] compare lists in Haskell
本文介绍了比较Haskell中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试比较Haskell中的两个列表,并找到了一个答案此处
我不知道如何
全部(flip elem listx)输入
特别是
div class =h2_lin>解决方案
-
flip elem listx
等效于elem)listx
。 -
(flip elem)
与elem
相同,参数以相反的顺序。这是翻转
的作用。 -
elem
元素和列表,并检查元素是否属于列表。 - 因此
flip elem
是一个函数,和一个元素,并检查元素是否属于列表。 - 因此
翻译elem listx
是一个函数, ,并检查元素是否属于listx
。 - 现在
全部
一个谓词和一个列表,并检查列表中的所有元素是否都满足谓词。 -
all(flip elem listx)
列表,并检查列表的所有元素是否满足flip elem listx
。也就是说,它们是否全部属于listx
。 -
all(flip elem listx)input
检查输入
的所有元素是否属于listx
。 - QED
I've been trying to compare two lists in Haskell and found an answer here
I wonder how
all (flip elem listx) input
works especially for the role flip plays here.
When I take out flip it won't work anymore.
解决方案
flip elem listx
is equivalent to(flip elem) listx
.(flip elem)
is the same aselem
, but with the arguments in opposite order. This is whatflip
does.elem
is a function that takes an element and a list, and checks whether the element belongs to the list.- So
flip elem
is a function that that takes a list and an element, and checks whether the element belongs to the list. - Therefore
flip elem listx
is a function that that takes an element, and checks whether the element belongs tolistx
. - Now
all
takes a predicate and a list, and checks whether all elements of the list satisfy the predicate. all (flip elem listx)
take a list, and checks whether all elements of the list satisfyflip elem listx
. That is, whether they all belong tolistx
.all (flip elem listx) input
checks whether all elements ofinput
belong tolistx
.- Q.E.D.
这篇关于比较Haskell中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文