[mercury-users] Libraries and DCG convenience...
Peter Ross
petdr at cs.mu.OZ.AU
Tue Jun 22 23:26:44 AEST 1999
On 21-Jun-1999, Luke Evans <Luke.Evans at seagatesoftware.com> wrote:
> Threading the graph variables through all this is painful and seems (IMHO)
> to be exactly what DCG's were designed for. Of course, I can write
> wrappers for the standard predicates which reorder the arguments to present
> the <Graph state before> and <Graph state after> arguments at the end of the
> argument list, but this becomes a real overhead to using the standard
> library.
>
You can use higher-order functions to avoid writing wrapper functions.
:- module main.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module graph, std_util.
main -->
{ graph__init(G0) },
{ create_graph(G0, G) },
io__write(G).
:- pred create_graph(graph(int), graph(int)) is det.
create_graph -->
switch(graph__det_insert_node, 1, Node1),
switch(graph__det_insert_node, 2, Node2),
switch(graph__det_insert_node, 3, Node3),
switch(graph__det_insert_edge, Node1, Node2, unit, _Arc12),
switch(graph__det_insert_edge, Node2, Node3, unit, _Arc23).
:- pred switch(pred(T, A, B, T), A, B, T, T).
:- mode switch(pred(in, in, out, out) is det, in, out, in, out) is det.
switch(P, A, B, T0, T) :-
P(T0, A, B, T).
:- pred switch(pred(T, A, B, C, D, T), A, B, C, D, T, T).
:- mode switch(pred(in, in, in, in, out, out) is det,
in, in, in, out, in, out) is det.
switch(P, A, B, C, D, T0, T) :-
P(T0, A, B, C, D, T).
--------------------------------------------------------------------------
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