[mercury-users] Tuple type class instances
Ralph Becket
rbeck at microsoft.com
Wed Jun 20 19:13:53 AEST 2001
> From: Michael Day [mailto:mikeday at corplink.com.au]
> Sent: 20 June 2001 02:02
>
> Is it or will it ever be possible to declare a type class instance
that
> applies to all tuples?
>
> I seem to recall this syntax...
>
> :- instance something({A | B}) ...
Well, right now {}/j and {}/k are different types if j \= k.
You can split tuples using reflection, but even if you wrote
a utility pred to do just that, you'd have to do a dynamic
cast on its outputs... ugh:
% Splits a tuple {X1, X2, ...} into X1 and {X2, ...}.
%
:- pred split(T1::in, T2::out, T3::out) is det.
If you want to use fixed size vectors, you'd probably be
better off using arrays, provided you're happy to constrain
each element to have the same type or use existential
types. The overhead of using arrays is just one word of
storage.
- Ralph
--------------------------------------------------------------------------
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