8
I am trying to find the list with the smallest sum of elements.:
shortest :: (Num a) => [[a]] -> [a]
shortest [] = []
shortest (x:xs) = if sum x < sum (shortest xs) then x else shortest xs
That gives me the following error:
Could not deduce (Ord a) arising from a use of `<' from the context (Eq a) bound by the type signature for shortest :: Eq a => [[a]] -> [a] at code.hs:(8,1)-(9,71) Possible fix: add (Ord a) to the context of the type signature for shortest :: Eq a => [[a]] -> [a] In the expression: sum x < sum (shortest xs) In the expression: if sum x < sum (shortest xs) then x else shortest xs In an equation for `shortest': shortest (x : xs) = if sum x < sum (shortest xs) then x else shortest xs
Why doesn't the function typecheck?