[m-dev.] io streams
Peter Schachte
schachte at cs.mu.OZ.AU
Tue Jan 4 15:19:11 AEDT 2000
On Tue, Jan 04, 2000 at 02:03:54PM +1100, David Glen JEFFERY wrote:
> Then, in each instance declaration where you want to use the default, you
> can just say:
>
> :- instance stream__input(mytype) where [
> pred(read_char/3) is mytype_read_char,
> pred(read_chars/3) is default_read_chars
> ].
>
> This is perhaps a minor inconvenience, but also arguably a good way of doing
> things.
The amount of inconvenience of this approach will be directly
proportional to the number of default methods one would like and
inversely proportional to the number of non-default methods. If there
are 10 default methods and 100 non-default ones, this doesn't look too
bad. If there are 10 default methods and 1 non-default, it looks
terrible.
I suspect I'd tend to want a lot of default methods, as they would
allow both simplicity and flexibility in instance definitions, but
until I use type classes a bit, I don't really know.
Another option would be to define this as two classes, eg,
stream__input/1 and stream__block_input/1, where the former is a
subclass of the latter with your default_read_chars/3 as its
read_chars/3 method. (Can this be done?) This would avoid the need
to mention the read_chars/3 method in instance declarations where the
default is wanted. Of course, this works rather badly when there are
several methods that might independently want defaults, and it has the
nuisance of needing to make up a lot of rather silly class names.
--
Peter Schachte The hottest places in hell are reserved
mailto:schachte at cs.mu.OZ.AU for those who, in time of great moral
http://www.cs.mu.oz.au/~schachte/ crisis, maintain their neutrality.
PGP: finger schachte at 128.250.37.3 -- Dante
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list