The type signature of foldr is:
foldr :: (a -> b -> b) -> b -> [a] -> b
In particular, foldr takes three arguments, so your definition for min is missing
one value:
min xs = foldr (\ x y -> if x<y then x else y) ??? xs
In the case of sum = foldr (+) 0, the argument 0 is the value of sum on the empty list.
Likewise, the missing argument ??? should be the value for min on the empty list. But does min [] even make any sense?
The way to resolve this is to realize that min should only be called on non-empty lists and write:
min [] = error "min called on an empty list"
min (a:as) = foldr (\x y -> if x < y then x else y) ??? as
To determine what ??? should be, just ask yourself: what should min (a:as) be when as = []?
minis already defined in Data.Ord. Although it looks like you may wantminimumfrom Data.List. Latices are semigroups andMaybelifts semigroups to monoids, so you could also define a Min Monoid nad useData.Foldable.foldMap. - Boyd Stephen Smith Jr.