比较Haskell中的列表 [英] compare lists in Haskell

查看:187
本文介绍了比较Haskell中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试比较Haskell中的两个列表,并找到了一个答案此处

我不知道如何
全部(flip elem listx)输入
特别是


div class =h2_lin>解决方案


  1. flip elem listx 等效于 elem)listx

  2. (flip elem) elem 相同,参数以相反的顺序。这是翻转的作用。

  3. elem 元素和列表,并检查元素是否属于列表。

  4. 因此 flip elem 是一个函数,和一个元素,并检查元素是否属于列表。

  5. 因此翻译elem listx 是一个函数, ,并检查元素是否属于 listx

  6. 现在全部一个谓词和一个列表,并检查列表中的所有元素是否都满足谓词。

  7. all(flip elem listx)列表,并检查列表的所有元素是否满足 flip elem listx 。也就是说,它们是否全部属于 listx

  8. all(flip elem listx)input 检查输入的所有元素是否属于 listx

  9. 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.

解决方案

  1. flip elem listx is equivalent to (flip elem) listx.
  2. (flip elem) is the same as elem, but with the arguments in opposite order. This is what flip does.
  3. elem is a function that takes an element and a list, and checks whether the element belongs to the list.
  4. So flip elem is a function that that takes a list and an element, and checks whether the element belongs to the list.
  5. Therefore flip elem listx is a function that that takes an element, and checks whether the element belongs to listx.
  6. Now all takes a predicate and a list, and checks whether all elements of the list satisfy the predicate.
  7. all (flip elem listx) take a list, and checks whether all elements of the list satisfy flip elem listx. That is, whether they all belong to listx.
  8. all (flip elem listx) input checks whether all elements of input belong to listx.
  9. Q.E.D.

这篇关于比较Haskell中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆