[mercury-users] Dispatch tables? Curried functions?

David Overton dmo at cs.mu.OZ.AU
Wed Jun 5 15:52:59 AEST 2002

On Wed, Jun 05, 2002 at 04:18:11AM +0000, Douglas Michael Auclair wrote:
> Hello, all,
> I wish to create a map that has string keys and function values to use as a 
> dispatch table.  The problem I have is that predicate lookup/3 returns the 
> function in the ground state, not the state of the function (e.g.: 
> func((ground -> ground), (ground -> ground)) = (free -> ground)) -- the 
> function lookup also returns the function in the undesired ground state.
> I worked around this by creating a top-level predicate with the appropriate 
> type qualifications (see next paragraph).  Is that the only way to go?  Is 
> it possible to create dispatch tables using maps?  How would this be done?

Last year I made a change to the mode checker so that it now assumes that
any object with a function type but with `ground' inst really has the
inst `func(in, ....) = out is det'.  This change is not in the latest
official realease so you will need to download a "release of the day"
(ROTD) from our ftp site to use it.

> Another issue:  the documentation is clear on how to create predicates that 
> return predicates (by declaring the out parameter as type (e.g.) free -> 
> pred(in, out) is det).  But I'm not getting the syntax for predicates or 
> functions that return functions:  free -> func(int) = int doesn't work, nor 
> does free -> (func(int) = int).  What is the proper mode/instantiation for 
> a function that returns a function?

Try `free -> (func(in) = out is det)' or even `out(func(in) = out is det)'.
However, if you install a version of the compiler supporting the feature
mentioned about, the mode `out' will work fine (assuming your functions
have the default function modes).

David Overton      Computer Science and Software Engineering
PhD Student        The University of Melbourne   +61 3 8344 9159
Research Fellow    Monash University (Clayton)   +61 3 9905 5779
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