Вопрос

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.

Это было полезно?

Решение

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)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top