0
votes

I have the following Haskell program:

catlines = unlines . zipWith (\(n,l) -> show n ++ l) [0..]

main = putStrLn $ catlines ["A", "B"]

When I try to compile it, GHC gives the following error:

catlines.hs:1:41:
    Couldn't match expected type `b0 -> String' with actual type `[a0]'
    In the expression: show n ++ l
    In the first argument of `zipWith', namely
      `(\ (n, l) -> show n ++ l)'
    In the second argument of `(.)', namely
      `zipWith (\ (n, l) -> show n ++ l) [0 .. ]'

From what I know, this should compile. I have no idea what's wrong.

1
What is the type of zipWith?user824425

1 Answers

5
votes

The problem is that the function passed to zipWith should take two arguments, not a tuple. Try it like this:

zipWith (\n l -> show n ++ l)