[m-rev.] for review: combined higher-order types and insts
Mark Brown
mark at mercurylang.org
Fri Feb 5 00:44:22 AEDT 2016
On Thu, Feb 4, 2016 at 2:41 PM, Julien Fischer <jfischer at opturion.com> wrote:
>
> Hi Mark,
>
> On Sun, 31 Jan 2016, Mark Brown wrote:
>
>> Hi,
>>
>> This implements the new language feature that I proposed recently
>> under the heading of subtypes.
>>
>> Part of the change is that I've moved some code to a new module and
>> also modified it. This doesn't show up in a full diff very well, so
>> I've also attached the diff of just these modifications to the new
>> module.
>
>
> ...
>
>> Implement combined higher-order types and insts.
>>
>> These allow types to be defined in the following manner:
>>
>> :- type job ---> job(pred(int::out, io::di, io::uo) is det).
>
>
> ...
>
>> compiler/prog_rep_tables.m:
>> Ignore the new inst info for now.
>>
>> compiler/*.m:
>> Changes to conform to above.
>>
>> doc/refernce_manual.texi:
>
>
> s/refernce/reference/
Ok.
>> +Combined higher-order types and insts are currently only permitted
>> +as direct arguments of functors in discriminated unions.
>
>
> So the following would not (currently) be legal?
>
> :- type job(T) ---> job(T).
> :- type job == job(pred(int::out, io::di, io::uo) is det).
That's right. In fact, there's three reasons:
- it occurs on the right hand side of an equivalence type
- it occurs as the argument of a type constructor
- it occurs somewhere not inside a du functor definition.
All of these things are logical extensions of what is currently done,
and there are also others. I'll leave further analysis to the thread
on the developers list.
>
> You also lacking (invlaid) test cases for when the arguments of combined
> higher-order types and insts do not all of modes specified or when the
> determinism as been omitted etc. For example:
>
> :- type job ---> job(pred(int::in, io::di, io) is det).
>
> or:
>
> :- type job ---> job(pred(int::in, io::di, io::uo)).
See attached diff.
Some of the errors are not very pertinent, because the parser allows
for the type '::'/2 to be defined. Should it?
E.g., prior to my change the following was accepted:
:- type (A :: B) == {A, B}.
:- type in == int.
:- type f ---> f(pred(int::in)).
>
>
> Other than that, I think the change looks ok.
Thanks for the review.
Mark
-------------- next part --------------
diff --git a/tests/invalid/Mmakefile b/tests/invalid/Mmakefile
index 5af4259..8a1291a 100644
--- a/tests/invalid/Mmakefile
+++ b/tests/invalid/Mmakefile
@@ -88,6 +88,7 @@ SINGLEMODULE= \
circ_type3 \
circ_type5 \
combined_ho_type_inst \
+ combined_ho_type_inst_2 \
comparison \
complex_constraint_err \
conflicting_fs \
diff --git a/tests/invalid/combined_ho_type_inst_2.err_exp b/tests/invalid/combined_ho_type_inst_2.err_exp
new file mode 100644
index 0000000..a80329c
--- /dev/null
+++ b/tests/invalid/combined_ho_type_inst_2.err_exp
@@ -0,0 +1,28 @@
+combined_ho_type_inst_2.m:015: In type definition: error: ill-formed type
+combined_ho_type_inst_2.m:015: ((pred int) is semidet).
+combined_ho_type_inst_2.m:018: In type definition: error: ill-formed type
+combined_ho_type_inst_2.m:018: (pred((int :: in), int) is det).
+combined_ho_type_inst_2.m:021: In type definition: error: ill-formed type
+combined_ho_type_inst_2.m:021: (((func int) = (int :: out)) is det).
+combined_ho_type_inst_2.m:024: In type definition: error: ill-formed type
+combined_ho_type_inst_2.m:024: (((func int) = int) is det).
+combined_ho_type_inst_2.m:027: In the first argument of function symbol
+combined_ho_type_inst_2.m:027: `missing_detism_p' of the type
+combined_ho_type_inst_2.m:027: `combined_ho_type_inst_2.missing_detism_p'/0:
+combined_ho_type_inst_2.m:027: error: undefined type `::'/2.
+combined_ho_type_inst_2.m:027: In the first argument of function symbol
+combined_ho_type_inst_2.m:027: `missing_detism_p' of the type
+combined_ho_type_inst_2.m:027: `combined_ho_type_inst_2.missing_detism_p'/0:
+combined_ho_type_inst_2.m:027: error: undefined type `in'/0.
+combined_ho_type_inst_2.m:030: In the first argument of function symbol
+combined_ho_type_inst_2.m:030: `missing_detism_f' of the type
+combined_ho_type_inst_2.m:030: `combined_ho_type_inst_2.missing_detism_f'/0:
+combined_ho_type_inst_2.m:030: error: undefined type `::'/2.
+combined_ho_type_inst_2.m:030: In the first argument of function symbol
+combined_ho_type_inst_2.m:030: `missing_detism_f' of the type
+combined_ho_type_inst_2.m:030: `combined_ho_type_inst_2.missing_detism_f'/0:
+combined_ho_type_inst_2.m:030: error: undefined type `in'/0.
+combined_ho_type_inst_2.m:030: In the first argument of function symbol
+combined_ho_type_inst_2.m:030: `missing_detism_f' of the type
+combined_ho_type_inst_2.m:030: `combined_ho_type_inst_2.missing_detism_f'/0:
+combined_ho_type_inst_2.m:030: error: undefined type `out'/0.
diff --git a/tests/invalid/combined_ho_type_inst_2.m b/tests/invalid/combined_ho_type_inst_2.m
new file mode 100644
index 0000000..a793c9b
--- /dev/null
+++ b/tests/invalid/combined_ho_type_inst_2.m
@@ -0,0 +1,33 @@
+%---------------------------------------------------------------------------%
+% vim: ts=4 sw=4 et ft=mercury
+%---------------------------------------------------------------------------%
+%
+% Uses combined higher-order types and insts with incomplete syntax.
+%
+%---------------------------------------------------------------------------%
+
+:- module combined_ho_type_inst_2.
+:- interface.
+
+:- import_module list.
+
+:- type missing_modes_p
+ ---> missing_modes_p(pred(int) is semidet).
+
+:- type missing_modes_p2
+ ---> missing_modes_p2(pred(int::in, int) is det).
+
+:- type missing_modes_f
+ ---> missing_modes_f(func(int) = (int::out) is det).
+
+:- type missing_modes_f2
+ ---> missing_modes_f2(func(int) = int is det).
+
+:- type missing_detism_p
+ ---> missing_detism_p(pred(int::in)).
+
+:- type missing_detism_f
+ ---> missing_detism_f(func(int::in) = (int::out)).
+
+:- type avoid_spurious_warning == list(int).
+
More information about the reviews
mailing list