[Haskell-beginners] Question on : usage
Angus Comber
anguscomber at gmail.com
Mon Dec 23 13:55:12 UTC 2013
I am playing with concatenating lists so I start with this:
testconcat :: [[a]] -> [a]
testconcat [[]] = []
testconcat [(x:xs)] = x : xs
Now, testconcat [[]] and testconcat [[1,2]] works
So now I want to try with a 2nd inner list so I do this:
testconcat :: [[a]] -> [a]
testconcat [[]] = []
testconcat [(x:xs)] = x : xs
testconcat [(x:xs), (y:ys)] = x : xs : y : ys
and I get load error:
Couldn't match expected type `a' with actual type `[a]'
`a' is a rigid type variable bound by
the type signature for testconcat :: [[a]] -> [a]
at prog_haskell.hs:218:15
In the first argument of `(:)', namely `xs'
In the second argument of `(:)', namely `xs : y : ys'
In the expression: x : xs : y : ys
But this loads ok:
testconcat :: [[a]] -> [a]
testconcat [[]] = []
testconcat [(x:xs)] = x : xs
testconcat [(x:xs), (y:ys)] = x : xs
Even this line cannot be loaded:
testconcat [(x:xs), (y:ys)] = x : xs : []
Couldn't match expected type `a' with actual type `[a]'
`a' is a rigid type variable bound by
the type signature for testconcat :: [[a]] -> [a]
at prog_haskell.hs:218:15
In the first argument of `(:)', namely `xs'
In the second argument of `(:)', namely `xs : []'
In the expression: x : xs : []
Failed, modules loaded: none.
if x : xs works why not x : xs : <something else> ???
Can someone please explain?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131223/94f5b1fa/attachment.html>
More information about the Beginners
mailing list