Reputation: 385
I know we can use below pattern matching in Haskell:
sum :: (Num a) => [a] -> a
sum [] = 0
sum (x:xs) = x + sum xs
But why can’t we use [x] ++ xs
?
sum :: (Num a) => [a] -> a
sum [] = 0
sum ([x] ++ xs) = x + sum xs
Upvotes: 3
Views: 704
Reputation: 64740
You can pattern match using constructors and literals but not functions.
Upvotes: 5