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
You can pattern match using constructors and literals but not functions.
: a constructor?1:2:3:4:[].(\(x++y) -> y++x) "abcde" evaluate to?