[mercury-users] overloading predicates/functions
Fergus Henderson
fjh at cs.mu.OZ.AU
Sun Oct 3 16:36:19 AEST 1999
On 03-Oct-1999, Michael Day <mikeday at corplink.com.au> wrote:
>
> Is it possible to overload predicates or functions in Mercury by the type
> of their arguments, as well as the arity?
Yes, so long as the predicates or functions in question reside in
different modules, or different sub-modules.
> If not, how do people normally cope with functions that need to take
> several possible types, but not *every* possible type? By creating
> multiple names with suffixes like _float, _string, etc?
There's three alternatives:
- use multiple names with suffixes
(e.g. io__write_string, io__write_float in library/io.m)
- use ad-hoc overloading, and put overloaded versions
that would have the same module, name, and arity
into sub-modules
(e.g. see extras/complex_numbers)
- use type classes
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list