constant space `minimum'

Serge D. Mechveliani mechvel at botik.ru
Thu Sep 30 00:30:07 EDT 2004


On Wed, Sep 29, 2004 at 02:43:45PM +0100, Simon Peyton-Jones wrote:
> | I meant that the implementation like
> | 
> |              minimum [x]      = x
> |              minimum (x:y:xs) = if x > y then minimum (y:xs)
> |                                 else          minimum (x:xs)
> 
> It would be great if this was the defn of minimum in the Report. But it
> isn't.
> 
> Consider 
>  
> data T = T1 | T2
> instance Ord T where
>    min x T2 = T2
>    min x y   = error "urk"
> 
> Now try
> 	minimum [T1,T2,T2]
> your defn gives "urk", but the Report gives T2.
> 
> Stupid, I know, but that's what it says.
> 
> 
> So the best thing seems to be to give monomorphic instances of minimum
> for types where we know the instances!
> 
> Simon
> 

I thought naively that the Report function definitions can be treated 
more flexy, varied by implementations, with preserving some declared 
main properties.
But, probably, less freedom is allowed: treating of Bottom to be 
preserved and such.
All right.

-----------------
Serge Mechveliani
mechvel at botik.ru


More information about the Glasgow-haskell-users mailing list