[Haskell-cafe] Incorrectly inferring type [t]
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.,
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":
> concat'' [[[1,2],[3,4]],[]] 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:
> 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)
> 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.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe