[m-rev.] Re: for review: support currying multi-modes preds in special case

Peter Wang novalazy at gmail.com
Mon Apr 21 12:10:19 AEST 2008


On 2008-04-16, Peter Wang <novalazy at gmail.com> wrote:
> Estimated hours taken: 15
> Branches: main
> 
> Support currying of multi-moded predicates or functions when the mode to curry
> can be determined from the insts of the higher-order arguments. e.g.
> 

Interdiff.  Julien, was there anything else?


diff -u compiler/mode_errors.m compiler/mode_errors.m
--- compiler/mode_errors.m	16 Apr 2008 06:15:16 -0000
+++ compiler/mode_errors.m	21 Apr 2008 02:08:01 -0000
@@ -972,17 +972,11 @@
     PredName = pred_info_name(PredInfo),
     QualifiedName = qualified(PredModule, PredName),
     Arity = pred_info_orig_arity(PredInfo),
-    (
-        PredOrFunc = pf_predicate,
-        Arity1 = Arity
-    ;
-        PredOrFunc = pf_function,
-        Arity1 = Arity - 1
-    ),
+    adjust_func_arity(PredOrFunc, FuncArity, Arity),
     Pieces = [words("mode error in unification of"),
         words(add_quotes(mercury_var_to_string(VarSet, no, X))),
         words("and higher-order term based on multi-moded"),
-        p_or_f(PredOrFunc), sym_name_and_arity(QualifiedName / Arity1),
+        p_or_f(PredOrFunc), sym_name_and_arity(QualifiedName / FuncArity),
         suffix("."), nl],
     Spec = error_spec(severity_error, phase_mode_check(report_in_any_mode),
         [simple_msg(Context, [always(Preamble ++ Pieces)])]).
@@ -1002,18 +996,12 @@
     PredName = pred_info_name(PredInfo),
     QualifiedName = qualified(PredModule, PredName),
     Arity = pred_info_orig_arity(PredInfo),
-    (
-        PredOrFunc = pf_predicate,
-        Arity1 = Arity
-    ;
-        PredOrFunc = pf_function,
-        Arity1 = Arity - 1
-    ),
+    adjust_func_arity(PredOrFunc, FuncArity, Arity),
     Pieces = [words("In unification of"),
         words(add_quotes(mercury_var_to_string(VarSet, no, X))),
         words("and higher-order term."),
         words("Could not determine the mode of"),
-        p_or_f(PredOrFunc), sym_name_and_arity(QualifiedName / Arity1),
+        p_or_f(PredOrFunc), sym_name_and_arity(QualifiedName / FuncArity),
         words("by the insts of the higher-order arguments only."), nl],
     Spec = error_spec(severity_error, phase_mode_check(report_in_any_mode),
         [simple_msg(Context, [always(Preamble ++ Pieces)])]).
diff -u doc/reference_manual.texi doc/reference_manual.texi
--- doc/reference_manual.texi	16 Apr 2008 06:15:20 -0000
+++ doc/reference_manual.texi	21 Apr 2008 02:08:05 -0000
@@ -4161,8 +4161,10 @@
 the modes default to @samp{in} for the arguments, @samp{out} for the
 function result, and the determinism defaults to @samp{det}.
 
-If the predicate or function has more than one mode, you must use an explicit
-lambda expression to specify which mode you want.
+The Melbourne Mercury implementation currently requires that you use an
+explicit lambda expression to specify which mode you want, if the predicate
+or function has more than one mode (but see below for an exception to this
+rule).
 
 You can also create higher-order function terms of non-zero arity
 and higher-order predicate terms by ``currying'',
@@ -4186,10 +4188,11 @@
 binds @samp{Double} to a higher-order function term of type
 @samp{func(list(int)) = list(int)}.
 
-The restriction on not creating higher-order terms from multi-moded
-predicates or functions is lifted if the mode of the curried predicate or
-function can be determined from the insts of its higher-order curried
-arguments.
+As a special case, currying of a multi-moded predicate or function is allowed
+provided that the mode of the predicate or function can be determined from
+the insts of the higher-order curried arguments.  For example,
+ at samp{P = list.foldl(io.write)} is allowed because the inst of @samp{io.write}
+matches exactly one mode of @samp{list.foldl}.
 
 For higher-order predicate expressions that thread an accumulator
 pair, we have syntax that allows you to use DCG notation in the


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list