Haskell中两个列表的所有元素组合 [英] All combinations of elements of two lists in Haskell
本文介绍了Haskell中两个列表的所有元素组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定两个列表,[a, b]
和 [c, d]
,我想得到以下结果:
Given two lists, [a, b]
and [c, d]
, I'd like to get the following result:
[(a,c), (a,d), (b,c), (b,d)]
如何在 Haskell 中做到这一点?是否有一个内置函数,或者我应该自己实现一个?
How can I do this in Haskell? Is there a built-in function for this, or should I implement one myself?
推荐答案
[ (x,y) | x<-[a,b], y<-[c,d] ]
这真的不需要任何进一步的解释,不是吗?
This doesn't really require any further explanation, does it?
这篇关于Haskell中两个列表的所有元素组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文