[Haskell-cafe] Incorrectly inferring type [t]

Lennart Augustsson lennart at augustsson.net
Thu Dec 30 05:42:39 CET 2010


First, what type would such a function have?
Certainly not [a]->[b], because that type say that it can take a list of any
type and turn it into a list of any other type, e.g.,
[Int]->[Bool].


On Thu, Dec 30, 2010 at 4:05 AM, william murphy <will.t.murphy at gmail.com>wrote:

> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101230/d144e431/attachment.htm>


More information about the Haskell-Cafe mailing list