[mercury-users] constructor class syntax

Peter Schachte schachte at cs.mu.OZ.AU
Fri Nov 5 14:52:43 AEDT 1999


On Fri, Nov 05, 1999 at 10:03:32AM +1300, Richard A. O'Keefe wrote:
[sorry, I've lost who Richard was quoting here...]
> 	By the way, Perl has records indexed by name (hashes).
> 	Dare I suggest Mercury should adopt '$record{field}' ?

Of course, maps in Mercury have similar functionality.  A syntax
similar to what you're asking for, and I think rather appealing, is
actually not that far away.  All that's really necessary is for a type
to be able to specify a function to invoke when an instance of that
type is used as a function (ie, applied to some arguments in a value,
as opposed to a goal, context).  Maybe something like this:

     :- type map(K,V) ---> ...
	where function_call is map__lookup.

:- func map__lookup(map(K,V), K) = V.

then, eg, if Map is bound to a map(string,int), you could write

      Value = Map("some key"),

to perform a map lookup.  The same trick would work nicely for arrays.
I think that's at least as nice as $map{"some key"}.  It's just
syntactic sugar, but it would make the language a little sweeter.
BTW, it would also be useful to be able to specify what predicate to
call when an instance of a type is called as a predicate.

> Mercury already
> _has_ dictionaries.  For field access, the "abstract pattern" stuff
> I presented at the Erlang conference last year would adapt to Mercury
> very nicely, and would actually be in the spirit of Mercury.

Could you post a URL for the paper, or let us know where it's published?

-- 
Peter Schachte                     Keeping the unrich gruntled constantly
mailto:schachte at cs.mu.OZ.AU        occupies our two political parties.
http://www.cs.mu.oz.au/~schachte/      -- Russell Baker 
PGP: finger schachte at 128.250.37.3  
--------------------------------------------------------------------------
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