Haskell quiz: a simple function

Posted by levy on Stack Overflow See other posts from Stack Overflow or by levy
Published on 2010-03-23T14:43:28Z Indexed on 2010/03/23 15:33 UTC
Read the original article Hit count: 234

Filed under:

I'm not a Haskell programmer, but I'm curious about the following questions.

Informal function specification:

Let MapProduct be a function that takes a function called F and multiple lists. It returns a list containing the results of calling F with one argument from each list in each possible combination.

Example:

Call MapProduct with F being a function that simply returns a list of its arguments, and two lists. One of the lists contains the integers 1 and 2, the other one contains the strings "a" and "b". It should return a list that contains the lists: 1 and "a", 1 and "b", 2 and "a", 2 and "b".

Questions:

  • How is MapProduct implemented?
  • What is the function's type? What is F's type?
  • Can one guess what the function does just by looking at its type?
  • Can you handle inhomogeneous lists as input? (e.g. 1 and "a" in one of the input lists)
  • What extra limitation (if any) do you need to introduce to implement MapProduct?

© Stack Overflow or respective owner

Related posts about haskell