On Fri, 6 Nov 1998, Christian Sievers wrote:

 | This gives one more example of what I always wanted to suggest:
 | The documentation of a class should clearly state which the minimal
 | sets of definitions are that one has to give, rather than let the
 | reader figure this out from the code.

Indeed! Or better: let the compiler give a warning in this case.

 | The default for (==) however seems odd to me. Someone could like to
 | define (==) alone or both (==) and (/=), but it seems strange to me to 
 | only define (/=). Or do you just want to give all expressible
 | relations?

No, look at the Num class:

  class (Eq a, Show a, Eval a) => Num a where
    (+), (-), (*)  :: a -> a -> a
    negate         :: a -> a
    abs, signum    :: a -> a
    fromInteger    :: Integer -> a
    fromInt        :: Int -> a

    x - y           = x + negate y
    fromInt         = fromIntegral

Clearly, one would like to define the following default definition as
well:

    negate x = 0 - x
    
Many classes suffer from this, this is just an example.

 | And while you're still doing non-hurting class definition changes, let 
 | me repeat this: please let succ and pred be Enum class members.

I agree!

I would also like to argue for the following extension:

  class Monad m where
    ...
    join mm = mm >>= id

Or, even better (but I might step too many people on their toes by this):

  class Functor m => Monad m where
    ...
    m >>= k = join (map k m)
    join mm = mm >>= id

Regards,
Koen.

--
Koen Claessen,
[EMAIL PROTECTED],
http://www.cs.chalmers.se/~koen,
Chalmers University of Technology.



Reply via email to