[mercury-users] passing higher-order modes to existentially typed data type wrappers

Jörg Roman Rudnick joerg.rudnick at t-online.de
Sun May 6 05:32:35 AEST 2007


Dear all,


I have another question about usage of existential types as wrappers: 
How about types with non-trivial (e.g. higher-order) modes? Is there a 
way to keep the modes of a contained type?

Just an example:

:-inst graphProblem --->
    graphProblem(
        %%  successor mapping:
        pred(in, out) is nondet
    ).

:-type graphProblem(NodeT) --->
    graphProblem(
        successorMapping::pred(NodeT, NodeT)
    ).


:-typeclass graphProblemI(GP, NodeT)
        <= ((GP -> NodeT), node(NodeT)) where [                       
                  
    func getSuccessorMapping(SP::in(searchProblem))=
        (pred(NodeT, NodeT)::out(pred(in,out) is nondet))
        is det
].

:-type xGraphProblem ---> some [GP, NodeT] (
    xGraphProblem(SP)
    => graphProblemI(GP, NodeT)
).


For conversion, I use the modes in/out at the moment:

:-func toXGraphProblem(GraphProblemT::in(graphProblem))=
        (*xGraphProblem::out*) is det
    <= graphProblemI(GraphProblemT, NodeT).

:-some [SearchProblemT2, StateT2, ActionT2, CostT2]
    func ofXGraphProblem(*xGraphProblem::in*)=
        (GraphProblem::out(graphProblem)) is det
    => graphProblemI(GraphProblemT, NodeT).


I would rather prefer to use the modes as in the enclosed
type's typeclass/inst - but at the moment, the following
would lead to "wrong instantiatedness" (toXGraphProblem/1)
and "inferred `failure'" determinism problems (ofXGraphProblem):

:-func toXGraphProblem(GraphProblemT::in(graphProblem))=
        (xGraphProblem::out(graphProblem)) is det
    <= graphProblemI(GraphProblemT, NodeT).

:-some [SearchProblemT2, StateT2, ActionT2, CostT2]
    func ofXGraphProblem(xGraphProblem::in(graphProblem))=
        (GraphProblem::out(graphProblem)) is det
    => graphProblemI(GraphProblemT, NodeT).


Altough it seems hard to imagine - might I have overseen a way
to use existentially quantified types with a mode identical to the
types they are enclosing?


Thank you in advance and all the best,

          Nick




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20070505/f68fb7da/attachment.html>


More information about the users mailing list