
Or you can try foldr1, which doesn't need a terminating value.
Here's its definition from the Standard Prelude
foldr1 :: (a -> a -> a) -> [a] -> afoldr1 _ [x]
= xfoldr1 f (x:xs) = f x (foldr1 f xs)foldr1 _ []
= errorEmptyList "foldr1"
On Mon, Mar 3, 2014 at 12:21 PM, Roelof Wobben
Thanks,
This did the job:
import Data.Char
x = foldr max 0 [5,10,2,8,1]
-- Note that comments are preceded by two hyphens {- or enclosed in curly brace/hypens pairs. -} main = print x
Roelof
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 listBeginners@haskell.orghttp://www.haskell.org/mailman/listinfo/beginners
------------------------------ http://www.avast.com/
Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirushttp://www.avast.com/actief is.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners