[mercury-users] Documentation error? Higher-order-inst example needs extra parentheses.
Ralph Becket
rafe at csse.unimelb.edu.au
Mon Feb 12 09:54:07 AEDT 2007
Julian Fondren, Saturday, 10 February 2007:
> >From the Mercury Language Reference Manual, section 8.3,
> Higher Order Modes:
>
> If you want to define a predicate which returns a higher-order
> predicate term, you would use a mode such as `free >> pred(...) is ...',
> or `out(pred(...) is ... )'. For example:
>
> :- pred foo(pred(int)).
> :- mode foo(free >> pred(out) is det) is det.
use `out(pred(out) is det)' rather than (free >> ...). It's more
readable.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined inst `in'/0.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined inst `func'/1.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined inst `>>'/2.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined inst `out'/0.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined inst `='/2.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined inst `det'/0.
> inst_fail.m:017: In mode declaration for predicate `inst_fail.foo'/1:
> inst_fail.m:017: error: undefined mode `is'/2.
>
> :- module inst_fail.
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is det.
> :- implementation.
> :- import_module int, list, string.
>
> main(!IO) :-
> foo(F),
> io.format("sum([1,2,3]) = %d\n", [i(F([1,2,3]))], !IO).
>
> :- func sum(list(int)) = int.
> sum([]) = 0.
> sum([H|T]) = H + sum(T).
>
> :- pred foo(func(list(int)) = int).
> :- mode foo(free >> func(in) = out is det) is det.
> foo(sum).
Place the `func(in) = out is det' in parentheses and your errors will go
away. The problem is that Mercury currently uses a precedence grammar -
it's a hangover from its Prolog heritage.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list