[mercury-users] ....use of solution/2

Stefan Hinterstoisser supersteveee at gmx.de
Mon Mar 22 14:20:29 AEDT 2004


Hi Ralph!

I just did it as you said, but somehow there is still a mistake in it and i
dont know where....

:- module inferenz.
:- interface.
:- import_module io.

:- pred main( io.state, io.state ).
:- mode main( di,       uo       ) is det.

:- implementation.
:- import_module int.
:- import_module list.
:- import_module std_util.


:- pred some_sublist( list(int), list(int) ).
:- mode some_sublist( in       , out       ) is multi.

some_sublist( [], [] ).
some_sublist( [X|Xs], [X|Ys] ) :- some_sublist( Xs, Ys ).
some_sublist( [_|Xs], Ys     ) :- some_sublist( Xs, Ys ).


main( !IO ) :-
  io.write_string("Start the Inferenz Program!\n", !IO ),
  Poss_list = ( solutions( some_sublist( [1,2,3,4] ) ) `with_type` list(int)
),
  io.write_string( "Solution of some_sublist ", !IO ),
  io.print( Poss_list , !IO ),
  io.nl( !IO ).


I got as error message inferenz.m:024: 
In clause for predicate `inferenz.main/2':
inferenz.m:024:   in argument 1 of functor `solutions/1':
inferenz.m:024:   type error in unification of argument
inferenz.m:024:   and functor `some_sublist/1'.
inferenz.m:024:   argument has type `(pred int)',
inferenz.m:024:   functor `some_sublist/1' has type 
inferenz.m:024:   `some_sublist((list.list(int))): (pred (list.list(int)))'.
        The partial type assignment was:
        Poss_list: (list.list(int))
        STATE_VARIABLE_IO_0: (io.state)
        STATE_VARIABLE_IO: (io.state)
        STATE_VARIABLE_IO_1: (io.state)
        V_8: string
        V_9: (io.state)
        V_10: (io.state)


Maybe the with_type is wrong? or because the compiler says something with
inferenz.m:024:   argument has type `(pred int)',
there is something wrong with that - but I cant find that mistake....
Thanx in advance,
Stefan


> Stefan Hinterstoisser, Sunday, 21 March 2004:
> > 
> > Thanx a lot for that... I`m just wondering if (because I looked it up
> > and I`m not quite sure about it) I can give the solution/2 predicate
> > also a predicate with several inputs (for sure only one output!)...
> 
> You can construct closures (or "partial applications") to do this.
> 
> For example,
> 
> 	Closure = find_route(Graph, Start, End),
> 	Routes = solutions(Closure),
> 	...
> 
> or equivalently just
> 
> 	Routes = solutions(find_route(Graph, Start, End)),
> 	...
> 
> where you have find_route defined as
> 
> :- pred find_route(graph, vertex, vertex, list(vertex)).
> :- mode find_route(in, in, in, out) is nondet.
> 
> > so would something like this work??
> > 
> > pred predicat(out, in, in) is nondet.  ...
>   ^^^^ I think you mean `mode' here.
> 
> The signature for solutions/1 is
> 
> :- func solutions(pred(T)) = list(T).
> :- mode solutions(pred(out) is multi) = out(non_empty_list) is det.
> :- mode solutions(pred(out) is nondet) = out is det.
> 
> so you'd either have to use a lambda to get things right
> 
> 	Closure = ( pred(X::out) is nondet :- predicat(X, A, B) ),
> 	Solutions = solutions(Closure),
> 	...
> 
> or a "wrapper" predicate to do the same thing:
> 
> 	Solutions = solutions(reordered_predicat(A, B)),
> 	...
> 
> where
> 
> :- pred reordered_predicat(..., ..., ...).
> :- mode reordered_predicat(in, in, out).
> 
> reordered_predicat(A, B, X) :- predicate(X, A, B).
> 
> -- Ralph
> --------------------------------------------------------------------------
> mercury-users mailing list
> post:  mercury-users at cs.mu.oz.au
> administrative address: owner-mercury-users at cs.mu.oz.au
> unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message:
> unsubscribe
> subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
> --------------------------------------------------------------------------
> 

-- 
+++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter Virenschutz +++
100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list