foldr1 :: (a -> a -> a) -> [a] -> a foldr1 _ [x] = x foldr1 f (x:xs) = f x (foldr1 f xs) foldr1 _ [] = errorEmptyList "foldr1"
Thanks,
This did the job:
import Data.Char
x = foldr max 0 [5,10,2,8,1]Roelof
-- Note that comments are preceded by two hyphens
{- or enclosed
in curly brace/hypens pairs. -}
main = print x
Emanuel Koczwara schreef op 2-3-2014 22:51:
Hi,
W dniu 02.03.2014 22:44, Roelof Wobben pisze:
Hello,
I now have to use foldr to find the max value in a list.
So I do this:
import Data.Char
x = foldr max [5,10,2,8.1]
-- Note that comments are preceded by two hyphens
{- or enclosed
in curly brace/hypens pairs. -}
main = print x
But now I see this error message:
main.hs@7:8-7:13
No instance for (Show ([[t0]] -> [t0])) arising from a use of `print' Possible fix: add an instance declaration for (Show ([[t0]] -> [t0])) In the expression: print x In an equation for `main': main = print x
Please look at foldr type and documentation. There is one argument missing in your code.
Regards,
Emanuel
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners