[mercury-users] undiscriminated unions
David Overton
dmo at cs.mu.OZ.AU
Thu Jan 10 22:42:29 AEDT 2002
On Thu, Jan 10, 2002 at 09:57:05PM +1100, Dave Slutzkin wrote:
> --- Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > Mercury does not support undiscriminated union
> > types.
> >
> > You can obtain a similar effect in one of two ways.
> >
> > The first is to use reflection (see how
> > pprint__to_doc/2 identifies
> > lists, arrays, tuples etc. for special treatment).
> >
> > The second is to use type classes.
> >
> > Out of interest, what's the problem you're trying to
> > solve that could
> > benefit from undiscriminated union types?
>
> Um, I was basically using them as a kind of simple
> record type. In fact, I initially had:
>
> :- module event.
>
> ...
>
> :- type event --->
> none
> ;
> event(
> type :: int,
> next :: event,
> ...
> ).
>
> Then I changed the way the events were stored, so a
> 'none' event no longer had any meaning or usefulness.
> Leaving me with an undiscriminated union. I wanted to
> still use the nice field access syntax and stuff. At
> the moment I've just reverted to the declaration with
> 'none'.
I think you mis-understand what an undiscriminated union type is. A
type declaration such as
:- type event --->
event(
type :: int,
next :: event,
...
).
with only one alternative is not an undiscriminated union, it is just a
plain record type (or a discriminated union with only one alternative).
It should work fine, including the field access syntax, in any recent
Mercury release.
An undiscriminated union would be a type such as
:- type num = int ; float.
This says that a num is either an int or a float, but there are no
functors to discriminate which one it is. This is not currently
supported by Mercury and IMHO is not ever likely to be (although if you
look at the compiler source code, there are some places where the
provision has been made to support these one day).
David
--
David Overton Department of Computer Science & Software Engineering
PhD Student The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159 http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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