list - Why can't ++ be used in pattern matching? -
From LearnYouAHaskell:
There is one more thing ???? You can not use ++ in pattern matching if you try to match the pattern against (xs ++ ys), what will happen in the first place and what will happen in the second list? It does not matter what it would be wise to match the stuff against (xs ++ [x, y, z]) or bus (xs + [x]), but due to the nature of the lists, you do not Can.
I am struggling to find out the reason for what it means by the nature of the lists, why can not it be so.
You match patterns against the creators, and there are two constructors for the list, empty list < Code> [] and 'cons'
: , where the two arguments of the opposition are the main and tail of the list.
++ is a function to attach two lists, so you can not match it.
If you can get against it, then
xs and
ys in pattern
xs ++ ys . For example, if you have also taken a small list like
[1] then there are two possibilities
xs == [] and ys == [1] xs = = [1] and ys == []
Therefore the match is ambiguous, which is about the quote.
Comments
Post a Comment