Haskell中两个列表元素的所有组合 [英] All combinations of elements of two lists in Haskell

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

问题描述

给出两个列表, [a,b] [c,d] ,我想得到以下结果:
$ b

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屋!

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