[Haskell-cafe] Incorrectly inferring type [t]

william murphy will.t.murphy at gmail.com
Thu Dec 30 04:05:03 CET 2010


Hi All,

I've spent a lot of time trying to write a version of concat, which
concatenates lists of any "depth":
So:
concat'' [[[1,2],[3,4]],[[5]]]               would return: [1,2,3,4,5]


The code is:
concat'' :: [a] -> [b]
concat'' ((y:ys):xs) = (concat'' (y:ys)) ++ (concat'' xs)
concat'' []          = []
concat'' (x:xs)      = (x:xs)


And the inevitable error is:
test.hs:298:12:
    Couldn't match expected type `a' against inferred type `[t]'
      `a' is a rigid type variable bound by
          the type signature for `concat''' at test.hs:297:13
    In the pattern: y : ys
    In the pattern: (y : ys) : xs
    In the definition of `concat''':
        concat'' ((y : ys) : xs) = (concat'' (y : ys)) ++ (concat'' xs)

test.hs:300:24:
    Couldn't match expected type `b' against inferred type `[t]'
      `b' is a rigid type variable bound by
          the type signature for `concat''' at test.hs:297:20
    In the first argument of `(:)', namely `x'
    In the expression: (x : xs)
    In the definition of `concat''': concat'' (x : xs) = (x : xs)
Failed, modules loaded: none.


Any help or advice would be appreciated.
Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101229/e9ea8628/attachment.htm>


More information about the Haskell-Cafe mailing list