> Summary: the Haskell 98 Report claims
>
> minimumBy :: (a -> a -> Ordering) -> [a] -> a
>
> but Hugs and GHC implement
>
> minimumBy :: (a -> a -> a) -> [a] -> a
> minimumBy = foldl1


The Haskell report says first
                       mimimumBy :: (a -> a -> Ordering) -> [a] -> a

in 7.7 - where the types are declared. And I like this.
In 7.8 it gives the "definition":
                              mimimumBy :: (a -> a -> a) -> [a] -> a
as  foldl min.
Which I dislike.
So, in my programs, I use

  minBy :: (a -> a -> Ordering) -> [a] -> a
  minBy _  [] = error "minBy _ []\n"
  minBy cp xs = m xs
                where  m [x]      = x
                       m (x:y:xs) = case  cp x y  of  GT -> m (y:xs)
                                                      _  -> m (x:xs)

And this implementation has also more chances to run without stack 
overflow.
Probably, it is good to improve  minimumBy  in this manner.
Also it agrees with the type of  sortBy.

Suggestion for standard library:
--------------------------------
to remove the names              minimum(By), maximum(By)
and to make                      min(By), max(By), gcd, lcm
for the lists only.
For example, 
             min [x,y],  min [x,y,x,u],  minBy compare [x,y,x,u]

             gcd [4,6],  gcd [4,6,4],    gcd [4]

This is for the economy of function names. Less names to recall.


------------------
Sergey Mechveliani
[EMAIL PROTECTED]








Reply via email to