[m-dev.] for review: record syntax [2]
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Wed Jan 5 18:05:31 AEDT 2000
On 04-Jan-2000, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> @@ -974,15 +842,341 @@
> FuncCall = call(PredId, ProcId, ArgVars, not_builtin,
> yes(FuncCallUnifyContext), QualifiedFuncName),
>
> + PredInfo = PredInfo0,
> Goal = FuncCall - GoalInfo0
> ;
> %
> + % Is it call to a field access function for
s/it call/it a call/
> Index: compiler/typecheck.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
> retrieving revision 1.268
> diff -u -u -r1.268 typecheck.m
> --- typecheck.m 1999/12/08 09:44:56 1.268
> +++ typecheck.m 1999/12/20 04:00:07
> + %
> + % For a field access function for which the user has supplied
> + % a declaration but no clauses, add a clause
> + % 'foo:='(X, Y) = 'builtin foo:='(X, Y).
> + %
> +:- pred maybe_add_default_field_access_clauses(module_info,
> + pred_info, pred_info).
> +:- mode maybe_add_default_field_access_clauses(in, in, out) is det.
It seems a bit weird to be doing this as part of typecheck. Couldn't it be
done earlier?
> + % XXX This demonstrates a problem - if a
> + % type variable occurs in the types of multiple
> + % fields, any predicates changing values of
> + % one of these fields cannot change their types.
> + % This especially a problem for existentially typed
> + % fields, because setting the field always changes
> + % the type.
> + %
> + % Haskell gets around this problem by allowing
> + % multiple fields to be set by the same expression.
> + % Haskell doesn't handle all cases -- it is not
> + % possible to get multiple existentially typed fields
> + % using record syntax and pass them to a function
> + % whose type requires that the fields are of the
> + % same type. It probably won't come up too often.
I'll talk to you about this in person at some stage.
> +:- pred write_comma_separated_error_list(pred(T, io__state, io__state),
> + list(T), io__state, io__state).
> +:- mode write_comma_separated_error_list(pred(in, di, uo) is det, in,
> + di, uo) is det.
> +
> +write_comma_separated_error_list(_, []) --> [].
> +write_comma_separated_error_list(Pred, [Error | Errors]) -->
> + Pred(Error),
> + write_comma_separated_error_list_2(Pred, Errors).
This is just io__write_list
> Index: doc/reference_manual.texi
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.162
> diff -u -u -r1.162 reference_manual.texi
> --- reference_manual.texi 1999/12/13 13:30:47 1.162
> +++ reference_manual.texi 2000/01/04 05:27:34
> + at item @var{Term} := ^ @var{Field1} ^ ... ^ @var{FieldN}
> +Unifies @var{Term} with the field of the implicit DCG argument
> +labelled by @var{Field}.
> + at var{Term} must be a valid data-term.
> + at var{Field1} @dots{} @var{FieldN} must be valid field names.
> + at xref{Record syntax}.
You talk here about "valid field names", but you haven't defined that yet.
(This may or may not be a problem).
> + at menu
> +* Builtin types::
> +* User-defined types::
> +* Predicate and function types::
> +* Field access functions::
> + at end menu
Is this part of the change related to the record syntax additions? If not, it
should really be a separate change.
[ I'm not too fussed, though. If it is hard
to separate the change, don't bother ].
> + at node Field extraction
> + at subsection Field extraction
> +
> + at example
> + at var{Field}(@var{Term})
> + at end example
> +
> +Each field label @samp{@var{Field}} in a constructor causes generation
> +of a field extraction function @samp{@var{Field}/1}, which takes a data-term
> +of the same type as the constructor and returns the value of the
> +labelled field, failing if the top-level constructor of the argument
> +is not the constructor containing the field.
> +
> +By default, this function has no modes --- the modes are inferred at
> +each call to the function.
I don't think "no modes" is the right thing to say. It is really
polymorphically moded (although that is probably a concept that is unfamiliar
to most of the readers of the document).
> + at node Field update
> + at subsection Field update
> +
> + at example
> +'@var{Field}:='(@var{Term}, @var{ValueTerm})
> + at end example
> +
> +Each field label @samp{@var{Field}} in a constructor causes generation
> +of a field update function @samp{'@var{Field}:='/2}.
> +The first argument of this function is a data-term of the same type as the
> +constructor. The second argument is a data-term of the same type as the
> +labelled field. The return value is a copy of the first argument with
> +value of the labelled field replaced by the second argument.
> + at samp{'@var{Field}:='/2} fails if the top-level constructor of the
> +first argument is not the constructor containing the labelled field.
> +
> +By default, this function has no modes --- the modes
> +are inferred at each call to the function.
Ditto.
> Index: tests/hard_coded/Mmakefile
> ===================================================================
> RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
> retrieving revision 1.73
> diff -u -u -r1.73 Mmakefile
> --- Mmakefile 1999/11/17 02:13:56 1.73
> +++ Mmakefile 1999/12/21 03:33:34
> Index: tests/hard_coded/record_syntax.exp
> ===================================================================
> RCS file: record_syntax.exp
> diff -N record_syntax.exp
> --- /dev/null Tue Jan 4 16:29:29 2000
> +++ record_syntax.exp Wed Dec 22 12:49:02 1999
> Index: tests/invalid/Mmakefile
> ===================================================================
> RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
> retrieving revision 1.56
> diff -u -u -r1.56 Mmakefile
> --- Mmakefile 1999/12/27 11:07:33 1.56
> +++ Mmakefile 2000/01/04 03:41:55
> Index: tests/invalid/record_syntax_errors.err_exp
> ===================================================================
> RCS file: record_syntax_errors.err_exp
> diff -N record_syntax_errors.err_exp
> --- /dev/null Tue Jan 4 16:29:29 2000
> +++ record_syntax_errors.err_exp Thu Dec 23 11:55:41 1999
You have not supplied the .m files for the test cases. I would like to see
those before you commit.
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student, | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.| With sufficient formality
The University of Melbourne | The sheerist banality
Australia | Will be hailed by the critics: "Miraculous!"
| -- Anon.
--------------------------------------------------------------------------
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