Question

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.

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top