views:

27

answers:

2

Hey I'm just revising for my functional programming exam coming up on friday and I'm just working through exercises given by our lecturer. I've come across one which I neep a bit of help on:

6. a) Write a function that zips a given list xs with every list in a list yss of lists. Use partial applications and lambda expressions to the greatest extent possible in defining your function. b) Write a function that zips every list in a list yss of lists with a given list xs. Use partial applications and lambda expressions to the greatest extent possible in defining your function. The difference between your solutions to part a) and part b) of this problem illustrates that partially applied functions must take their arguments in the correct order.

What I have at the moment for (a) is :

zipAll = (\xs (ys:yss) -> [(zip xs ys)] ++ zipAll xs yss)

It's non-exaustive I know but could anyone give me some pointers?

+1  A: 

It seems like you are just missing your base case to make the function work. The base case would be

(\xs [ys] -> [(zip xs ys)])

I would probably move the parameters to the right side of the equation instead:

zipAll xs (ys:yss) = ...

but that is just at matter of style.

The solution for part (b) is the same, except that the order of the parameters is reversed, like

zipAll (ys:yss) xs = ...
Jørgen Fogh
cheers, I apreciate it :)
ChrisMacDee
A: 

Its fine, I worked it out:

zipList :: [a] -> [[b]] -> [[(a,b)]]
zipList = \xs yss -> c xs yss
                        where
                                c xs [] = []
                                c xs (ys:yss) = zip xs ys :zipList xs yss

Just wish I hadn't posted this now :P

ChrisMacDee