[m-dev.] Polymorphic modes

David Overton dmo at cs.mu.OZ.AU
Wed May 2 11:45:04 AEST 2001


On Tue, May 01, 2001 at 07:27:10AM -0700, Ralph Becket wrote:
> Talking to Tyson and Peter, it seems the compiler does now
> accept polymorphic modes (or at least some useful limited version
> thereof).  However, I can't find any mention of this in the
> documentation.  If there is some lying around, can someone post
> it here or, preferably, add it to the reference manual.

Yes, the compiler now accepts a limited form of mode-polymorphism.
You can place an inst variable in a mode declaration for a predicate
or function, but the inst is constrained to be a "sub-inst" of ground
(i.e. ground, bound(....) with all arguments ground, or a higher-order
inst).

e.g.

:- pred append(list(T), list(T), list(T)).
:- mode append(in(list_skel(I)), in(list_skel(I)), out(list_skel(I))) is det.

will allow you to append, say, two lists of functions.

Here are some notes on this from the 29/9/2000 Mercury meeting:

 David Overton :
                - Had been finishing off the change to support polymorphic modes
                  (i.e. allowing inst variables which can be instantatied
                  to any ground inst in mode declarations).
                  The problem with this change was performance --
                  mode checking for a version of tree234 using polymorphic
                  modes was 1 minute 45 seconds, as compared to 17 seconds
                  for the non-polymorphically moded version.
                  This is getting much too slow.
                  However, since the changes didn't slow down mode checking
                  of existing code, we agreed that it was OK to commit this
                  change, particularly since this would help other people
                  experiment with it, work on it, and perhaps fix the
                  performance problem. David Overton speculated that
                  the performance problem might not be fixable in the
                  current mode system implementation.

The performance problem is the main reason why this feature has not
yet been officially documented or used in the standard library.  I
have not had any time to work on this since September, but if you want
to try it out, any feedback would be appreciated.


David
-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list