[mercury-users] undiscriminated unions
Dave Slutzkin
dave_slutzkin at yahoo.com
Thu Jan 10 21:57:05 AEDT 2002
--- 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'.
Presumably I should be using a typeclass - although
that seems like a little overkill in this case. I'm
not sure what benfits it gets me. Although I guess I
do have a well-defined set of functions that apply to
events...
(I haven't read through the pprint__to_doc code yet.)
Are there any other advantages I should be
considering?
thanks,
Dave.
http://my.yahoo.com.au - My Yahoo!
- It's My Yahoo! Get your own!
--------------------------------------------------------------------------
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