I have stumbled across an error that was very confusing to me. I had a recursive function with the pattern matching ["",_] = []
which simply didnt work. After many times of trying to find my mistake I tried switching it up with ("":_) = []
. And it worked! I just want to know why the first term didnt work but the second one did.
This function works and the pattern matching is called:
takeAllElem :: [String] -> [String]
takeAllElem ("":_) = []
takeAllElem (xs) = map takeFirstElem (xs) : (takeAllElem (removeFirstElem (xs)))
This function also works but the pattern matching is never called:
takeAllElem :: [String] -> [String]
takeAllElem ["",_] = []
takeAllElem (xs) = map takeFirstElem (xs) : (takeAllElem (removeFirstElem (xs)))
Is this just a syntax error or does the compiler interpret ["",_]
differently to ("":_)
.