[m-dev.] alternative syntax for pred declarations.
David Matthew OVERTON
dmo at students.cs.mu.oz.au
Sun Nov 30 23:17:15 AEDT 1997
Thomas Charles CONWAY wrote:
>
> Hi
>
> I've been working on code which has lots of predicates that have
> the same arguments:
> :- pred this_parser(maybe(xxx), parse_state, parse_state).
>
> It would be nice to be able to write:
>
> :- type parser(T) == pred(maybe(T), parse_state, parse_state).
>
> :- mode parser :: (pred(out, in, out) is det).
>
> :- pred this_parser = parser(xxx).
> :- mode this_parser = parser.
>
> Comments?
I think something like this would be a great idea. It would be even
more useful if you could declare a predicate by concatenating a number
of different bits together, e.g.
:- type foo == pred(x, y, z).
:- mode foo :: (pred(out, in, out) is det).
:- pred bar(a, b) + foo.
:- mode bar(in, in) + foo.
The declaration of `bar' would be equivalent to
:- pred bar(a, b, x, y, z).
:- mode bar(in, in, out, in, out) is det.
An example of where this would be useful: say you have the following
defined:
:- type foo == pred(x, y, z).
:- mode foo :: (pred(in, in, out) is det).
:- pred use_foo(foo, result).
:- mode use_foo(foo, out) is det.
Then you want to write a number of predicates to pass as the first
argument of `use_foo', but you also want to have some
extra arguments at the start of the predicate which are curried before
passing the closure to `use_foo'. You could declare
such a predicate as:
:- pred bar(x, y) + foo.
:- mode bar(in, in) + foo.
Another place where this might be useful is with DCGs:
:- type io_op == pred(io__state, io__state).
:- mode io_op :: (pred(di, uo) is det).
:- pred write_something(something) + io_op.
:- mode write_something(in) + io_op.
write_something(Something) -->
...
Of course there may be times when you want a different determinism to
the one you have defined in your predicate mode. Maybe you could
override it like this:
:- pred do_some_io(x, y) + io_op.
:- mode do_some_io(in, out) + io_op is cc_multi.
This would ignore the `det' in the definition of `io_op' and use
`cc_multi' as the declared determinism of `do_some_io'.
Can anyone think of a better way to do this?
David
More information about the developers
mailing list