> 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. 

Good question.  The main reason for putting them *in* the class
decl is that it allows the possibility for an instance declaration
to supply a more efficient type-specific implementation of the method.

The down-side is that a client of the class does not know how a method
is implemented, whereas he does know how a function defined outside
the class is implemented.

(>>) is in Monad because conceivably it might be more efficient to
know that the result is not going to be used; but (=<<) is not
becuase it's just an argument-flipped version of (>>=), and so could
not possibly be implemented more efficiently.  But arguably sequence and
friends should be in Monad too?  It's hard to tell.

Bottom line: it's a judgement call

Simon



Reply via email to