[m-rev.] Re: for review: default modes for higher-order func insts

David Overton dmo at cs.mu.OZ.AU
Wed Oct 10 16:19:29 AEST 2001


On Wed, Oct 10, 2001 at 03:06:01PM +1000, Fergus Henderson wrote:
> On 10-Oct-2001, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > On Fri, Aug 03, 2001 at 09:44:37PM +1000, Fergus Henderson wrote:
> > > On 03-Aug-2001, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > > > Implement a change to the mode system suggested by Ralph Becket to
> > > > make use of higher order functions a bit easier.
> > > 
> > > There should really be some documentation of this in the Mercury language
> > > reference manual.
> > 
> > Documentation is still to come.  I would like to get this committed
> > though, so that people like Ralph and Michael who have been asking for
> > it can try it out.
> 
> I think it should not be committed until the patch includes appropriate
> documentation.  Otherwise the danger of it never being properly documented
> is too high.

Here is some documentation.


--- cvslog.old	Wed Oct 10 15:31:58 2001
+++ cvslog	Wed Oct 10 15:32:53 2001
@@ -1,5 +1,5 @@
 
-Estimated hours taken: 3
+Estimated hours taken: 8.5
 Branches: main
 
 Implement a change to the mode system suggested by Ralph Becket to make use of
@@ -45,3 +45,7 @@
 tests/invalid/ho_default_func_3.m:
 tests/invalid/ho_default_func_3.err_exp:
 	Add some test cases.
+
+NEWS:
+doc/reference_manual.tex:
+	Document the change.

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.219
diff -u -r1.219 NEWS
--- NEWS	25 Sep 2001 09:36:44 -0000	1.219
+++ NEWS	10 Oct 2001 05:38:29 -0000
@@ -2,6 +2,16 @@
 ----------------------------------
 
 Changes to the Mercury language:
+
+* If a higher-order function term has inst 'ground' it is now assumed to have
+  the standard higher-order function inst 'func(in, .., in) = out is det'.  
+  This makes higher-order functional programming much easier, particularly when
+  passing functions to polymorphic predicates.
+
+  This change is not backwards compatible since, for safety, we must now
+  disallow calls that would cause a variable that has a nonstandard function
+  inst to become 'ground'.
+
 * The constructor for lists is now called '[|]' rather than '.'.
   `./2' will eventually become the module qualification operator.
   This change only affects programs which use `./2' explicitly.
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.218
diff -u -r1.218 reference_manual.texi
--- doc/reference_manual.texi	3 Oct 2001 11:37:53 -0000	1.218
+++ doc/reference_manual.texi	10 Oct 2001 05:39:28 -0000
@@ -3435,6 +3435,22 @@
 example @samp{(list__append([], [P], [Q])} may result in an error at
 run-time rather than at compile-time.
 
+In order to call a higher-order term, the compiler must know its higher-order
+inst.  This can cause problems when higher-order terms are placed into a
+polymorphic collection type and then extracted, since the declared mode for the
+extraction will typically be @samp{out} and the higher-order inst information
+will be lost.
+To partially alleviate this problem, and to make higher-order functional
+programming easier, if the term to be called has a function
+type, but no higher-order inst information, we assume that it has the default
+higher-order function inst
+ at samp{func(in, @dots{}, in) = out is @var{Determinism}}.
+
+As a consequence of this, it is a mode error to pass a higher-order function
+term that does not match this standard mode to somewhere where its higher-order
+inst information may be lost, such as to a polymorphic predicate where the
+argument mode is @samp{in}.
+
 @node Modules
 @chapter Modules
 
-- 
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-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list