[mercury-users] 're-creating' higher order insts?
Ondrej Bojar
bojar at csse.unimelb.edu.au
Mon Oct 8 15:45:59 AEST 2007
Hi,
the chapter of Language Manual on higher-order modes says:
---
In order to call a higher-order term, the compiler must know its higher-order
inst. This can cause problems when higher-order terms are placed into a
polymorphic collection type and then extracted, since the declared mode for the
extraction will typically be `out' and the higher-order inst information will be
lost. To partially alleviate this problem, and to make higher-order functional
programming easier, if the term to be called has a function type, but no
higher-order inst information, we assume that it has the default higher-order
function inst `func(in, ..., in) = out is Determinism'.
---
I assume there is no way to reconstruct the lost higher order mode, apart from
supplying the higher order mode from outside, e.g.:
:- type magic_maker == (pred(int))
:- inst magic_maker == (pred(out) is det).
:- func construct_magic_maker = (magic_maker::out(magic_maker)) is det.
:- pred mypred(
map(string, magic_maker)::in
% plain 'in' because there is no inst map(K_inst, V_inst)
) is det.
mypred(MagicMakersPerKeyWord) :-
KeyWord = "keyword",
map.lookup(MagicMakersPerKeyWord, KeyWord, MagicMaker),
% MagicMaker is now ground, so it cannot be called
FakeMagicMaker = construct_magic_maker,
% call FakeMagicMaker instead
...
Am I correct that in general there is no use of storing a higher order value in
an ADT that does not explicitly allow extraction of the higher order value with
the correct inst? (E.g. list(T) allows that, because there is inst list(I) and
list deconstruction to head and tail honor the instantiatedness.) -- with the
exception of functions matching the default mode.
So in general, I have to store only some ground identifier and have a
(assoc_list) mapping from this identifier to the actual predicate. In the
example above, the identifier was void (construct_magic_maker had no input
argument), so construct_magic_maker could construct a single predicate only.
Or am I missing something?
Thanks, Ondrej.
--
Ondrej Bojar (mailto:obo at cuni.cz / bojar at ufal.mff.cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
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