[mercury-users] Library v2 and Typeclasses'n'Stuff

Juergen Stuber juergen at mpi-sb.mpg.de
Mon Nov 8 06:47:10 AEDT 1999


Ralph Becket <rbeck at microsoft.com> writes:

> > [...]
> > Not to forget exhaustiveness.  How about a mode declaration
> > for the corresponding disjunction, like this:
> > 
> > :- mode ([] = in ; [out,out] = in) is det.

I'd better make this

:- mode ([] = X :: in ; [out,out] = X :: in) is det.
 
to show the relation of the input arguments.

> Unfortunately for this case, disjunction isn't exclusive, although the
> `is det' declaration probably helps to disambiguate.

Yes, that is the point.

> However, what I think is needed is not a change to the mode system, but
> simply the adoption of the forthcoming promise mechanism with type
> qualification, e.g.
> 
> :- promise all [X:sequence(S, T)] (X = []) <=> \+ (X = [H | T]).

I guess that should be

:- promise all [X:S] (X = []) <=> \+ (X = [H | T]) <= sequence(S, T).

You can view modes as abbreviations of such formulas.
I think that some abbreviation is needed, because for
more than two alternatives the formulas get quite big and nasty.

> > I think it is really important to be able to use pattern matching
> > regardless of the actual data structure.  Otherwise people start
> > with the convenience of pattern matching on lists and cannot change
> > to other datatypes later.
> 
> We have to be careful not to confuse type constructors with typeclass
> functions.  For example, I may have a sequence type with several different
> `null's and several different `cons'es, yet still want basic sequencing
> operations to work.

I don't see the problem, can't you use the module system to
do the disambiguation?

Jürgen

-- 
Jürgen Stuber <juergen at mpi-sb.mpg.de>
http://www.mpi-sb.mpg.de/~juergen/
--------------------------------------------------------------------------
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