[mercury-users] Bit-fields in Mercury

Peter Schachte schachte at csse.unimelb.edu.au
Tue Jul 11 13:12:13 AEST 2006


On Tue, Jul 11, 2006 at 12:33:19PM +1000, Michael Day wrote:
> 
> > Could you give an example where that would be useful.  Why not just
> > ignore the argument(s) if you're not interested in them?
> 
> Being able to separate the name and the value allows you to write more
> generic code. For example, you can lookup/store things by name. If the
> name and value are coupled, then it's more difficult:
> 
> :- type opt
>     --->    opt1(int)
>     ;       opt2(string).

How about having a separate type for each kind of option, and a type
class for 'option'.  Then you could have to have methods for all the
different ways you want to handle the options, with a separate
implementation for each option.  That way each method can deal with
the data attached to each option in the appropriate way.  It might
wind up being too verbose and painful, and it may be awkward to have
the option handling all in separate methods rather than in one
predicate, but at least the type system won't get in your way, and
you'll still have type safety and ease of introducing new options.

-- 
Peter Schachte              The trouble with Communism is the Communists,
schachte at cs.mu.OZ.AU        just as the trouble with Christianity is the
www.cs.mu.oz.au/~schachte/  Christians.
Phone: +61 3 8344 1338          -- H.L. Mencken 
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at csse.unimelb.edu.au
administrative address: owner-mercury-users at csse.unimelb.edu.au
unsubscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: unsubscribe
subscribe:   Address: mercury-users-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list