(I meant to send this to the Haskell list this morning, but hit reply and
didn't get what I expected!)

-----Original Message-----
From: michael abbott [mailto:[EMAIL PROTECTED]]
Sent: 28 January 1999 10:13
To: 'Jose Emilio Labra Gayo'
Subject: RE: A simple question on Haskell style


The essential difference is the method dm in your example below isn't really
a "derived" method -- instead, you have presented a *default* definition of
dm which can be overridden by an instance of MyClass.

If your intention is that the definition of dm is fixed given a set of basic
MyClass methods then I think you should define dm outside the class.  On the
other hand, if you want to offer a sensible default definition of dm which
can optionally be replaced by an alternative definition for a particular
MyClass instance then you need to define dm as part of the class.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Jose Emilio Labra Gayo
Sent: 28 January 1999 08:39
To: [EMAIL PROTECTED]
Subject: A simple question on Haskell style


Suppose I define a new type class MyClass with some methods

class MyClass a where
        -- Basic methods
        m :: Some type including a
        ...

        -- Derived Methods
        dm :: Some type including a
        dm = Definition of dm that depends on m
        ...

However, I could remove the derived methods from
the class definition:

-- Derived Methods
dm :: (MyClass a) => Some type including a
dm = Definition of dm that depends on m
...

And my question is:

Is it better to type the derived methods inside the class
definition or out? Are there any efficiency penalties
in any of the styles?

In Haskell98 Prelude there is a mixture of both styles, for example,
(>>) is defined inside the Monad class, but (=<<) is left out.

Greetings, Jose E. Labra
http://lsi.uniovi.es/~labra





Reply via email to