[mercury-users] Dispatch tables? Curried functions?

Ralph Becket rafe at cs.mu.OZ.AU
Wed Jun 5 15:35:48 AEST 2002


Douglas Michael Auclair, Wednesday,  5 June 2002:
> 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.

Function insts of the form

	func(in, ..., in) = out is det

are sub-insts of ground.  You can have collections of them without
having to worry about modes.

The latest ROTD versions of the compiler support polymorphic modes
(necessary for more complex higher-order collections, such as preds and
non-det funcs), but we haven't got round to updating the modes in the
library yet.

> 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?
> 
> 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?

You're getting insts and types mixed up.
(free >> (func(in) = out is det)) is probably what you mean.

Note that it's easier and shorter to use the standard parametric modes,
such as out(func(in) = out is det).

> My work-around for this one is to package the function to be curried into a 
> locally declared predicate, call a predicate that returns the curried 
> predicate, and then unpackage that new predicate into a local function.  
> Quite a bother!  Is there a one-step way of currying functions?

Well, provided you're only interested in standard mode functions, you
don't actually need to do anything (other, perhaps, than to upgrade to a
recent ROTD.)

- Ralph
--------------------------------------------------------------------------
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