[mercury-users] list functor style functions

Michael Day mikeday at corplink.com.au
Fri Nov 12 02:15:06 AEDT 1999


Hi,

last week people debated creating a typeclass to allow other sequence
types to emulate the behaviour of lists by letting them be constructed in
the same way. My question is whether the following definitions are useful:

        func [] = C(T),
        mode [] = out is det,
        mode [] = in is semidet,

        func [T|C(T)] = C(T),
        mode [in|in] = out is det,
        mode [out|out] = in is semidet,

They would appear to me to allow use of any type that satisfies this type
class in the same way as lists. But I'm wondering if the definitions are
overly restrictive. For full compatibility with lists, the [] function has
to be used in two ways, to compare as an empty sequence and to create
empty sequences. As functions cannot specify different code for different
modes I'm guessing this will not always be possible, especially
considering the current standard library has always made the distinction
between `init' and `is_empty'. Similarly the code for prepend and
remove_head. Writing predicates to manipulate lists is nice, and it would
be great if they could be generalised to work with all kinds of sequences
and containers, but is it feasible with the current language design? Is it
desirable to have functions that work in many modes or separate them? I
would be interested to be able to say:

	X = sin(pi)

and

	1.0 = sin(X)

with the appropriate mode settings. I understand with the C interface I
can possibly do that, but should I *want* to do that? (Ignoring
compatibility with other languages use of asin(), and just focusing on the
issue of using functions in reverse and multiple modes, that may require
differing implementations).

Thanks,

Michael

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