I'm trying to calculate the length of the list using different methods (just to get familiar with the language). The function using pattern matching works as expected, whereas the one using guards throws an error.
After some digging I noticed that something is probably wrong with this line (x : xs) == [] = res, but I can't figure out what exactly. Any help would be much appreciated!
Using pattern matching (works as expected)
myLength1 list = go list 0
where
go [] res = res
go (x : xs) res = go xs (res + 1)
Using guards (throws Non-exhaustive patterns in function go)
myLength2 list = go list 0
where
go (x : xs) res
| (x : xs) == [] = res
| otherwise = go xs (res + 1)