RE: constant space `minimum'

| 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

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@botik.ru

I thought naively that the Report function definitions can be treated more flexy, varied by implementations, with preserving some declared main properties. The definitions in the Report are to be treated as specifications. Any implementation should have *exactly* the same denotation as
On Thu, 30 Sep 2004, Serge D. Mechveliani wrote: the function in the Report. What use would the Report be if you didn't treat it this way? -- Lennart
participants (3)
-
Lennart Augustsson
-
Serge D. Mechveliani
-
Simon Peyton-Jones