Aqui estou tentando reimplementar um máximo seguro usando dobras
import Data.ByteString (foldl')
maximum' :: Ord a => [a] -> Maybe a
maximum' = foldl (\ acc x -> max acc (Just x)) Nothing
maximum'' :: Ord a => [a] -> Maybe a
maximum'' = foldl' (\ acc x -> max acc (Just x)) Nothing
A primeira função que usa foldl está funcionando corretamente, mas a segunda dá este erro:
• Couldn't match expected type ‘a’
with actual type ‘GHC.Word.Word8’
‘a’ is a rigid type variable bound by
the type signature for:
maximum'' :: forall a. Ord a => [a] -> Maybe a
at /home/mali/Projects/Deneme/HigherOrder.hs:60:1-36
• In the first argument of ‘Just’, namely ‘x’
In the second argument of ‘max’, namely ‘(Just x)’
In the expression: max acc (Just x)
Não deveria foldl'
ser apenas uma versão mais eficiente de foldl
?