The Haskell Wikibook provides one
foldl1 :: (a -> a -> a) -> [a] -> a
foldl1 f (x:xs) = foldl f x xs
foldl1 _ [] = error "Prelude.foldl1: empty list"
that doesnt work. I tried to compile this version of it:
myFoldl1 :: (a -> a -> a) -> [a] -> a
mFoldl1 f (x:xs) = myFoldl1 f x xs
myFoldl1 _ [] = error "Prelude.foldl1: empty list
I first thought it was missing a case to end the fold and that there was a problem with the typing
foldl1 _ [x] = x
foldl1 f (x:xs) = foldl (f x) xs
But this wont work either. I think the type issue goes deeper, but I dont have a good enough grasp of Haskell to think further. Can someone help me out?