# [Haskell] 2 programs VERY URGENT

Mohammad Mehdi Bezyan mbezyan at yahoo.com
Sat Aug 12 08:23:37 EDT 2006

```Hello All

There are 2 questions for my project and I need to aswer them as soon as possible. The answers need to be written in Haskell using recursive methods.

The questions are the following:

Number 1:
The set of n-combinations of a set S is the set of subsets of S of size n. Write a function combs :: Int -> [a] -> [[a]] which, representing sets as lists, calculates n-combinations of a given list. For example, combs 3 [1,3,5,6,9] is [[1,3,5],[1,3,6],[1,3,9],[1,5,6],[1,5,9], [1,6,9],[3,5,6],[3,5,9],[3,6,9],[5,6,9]]
Within each combination, the n values should appear in the same order as they appear in the original list (so, for example, [1,5,3] should not appear instead of [1,3,5] in the result for combs 3 [1,3,5,6,9]). But the list of combinations may appear in any order (ie, [1,3,5] need not appear first in the result of combs 3 [1,3,5,6,9]). You may assume that the list argument to combs does not contain duplicate members.

Number 2:
Given a list of lists, a list is in the Cartesian product of them if it contains one member from each of them. Write a function cart :: [[a]] -> [[a]] which calculates this. For example, cart [[1,2], [4], [7,8,9]] is [[1,4,7],[1,4,8],[1,4,9],[2,4,7],[2,4,8],[2,4,9]]
Each member of the Cartesian product must appear in the appropriate order: eg, in [1,4,7] above, 1 appears first, then 4, then 7, because 1 is from the first input list [1,2], 4 is from the second input list [4], and 7 is from the third input list [7]. The list of members of the Cartesian product may appear in any order (ie, [1,4,7] need not appear first in the list).

It would be very much appreciated if you could help me or provide me with some code, please. I need them very soon.

Thanks!

Send instant messages to your online friends http://au.messenger.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...