Hi,

In the string module string__foldl is defined as...

:- func string__foldl(func(char, T) = T, string, T) = T.
:- pred string__foldl(pred(char, T, T), string, T, T).
:- mode string__foldl(pred(in, in, out) is det, in, in, out) is 
det.
:- mode string__foldl(pred(in, di, uo) is det, in, di, uo) is 
det.
:- mode string__foldl(pred(in, in, out) is semidet, in, in, out) 
is semidet.
:- mode string__foldl(pred(in, in, out) is nondet, in, in, out) is 
nondet.
:- mode string__foldl(pred(in, in, out) is multi, in, in, out) is 
multi.
%	string__foldl(Closure, String, Acc0, Acc):
%	`Closure' is an accumulator predicate which is to be called for 
each
%	character of the string `String' in turn. The initial value of 
the
%	accumulator is `Acc0' and the final value is `Acc'.
%	(string__foldl is equivalent to
%		string__to_char_list(String, Chars),
%		list__foldl(Closure, Chars, Acc0, Acc)
%	but is implemented more efficiently.)


Closure is said to be an accumulator predicate which means that it 
stores the intermediate results.

I would like to know how do I use it along with string__foldl.

Should I create a type like
:- type silly_type --> number(int); couple(int, int)
or a similar type

and a predicate
:- pred print_silly_type(silly_type, io__state, io__state).
:- mode print_silly_type(in, di, uo).
or  aa similar predicate

and implement it as
print_silly_type(MyType) -->
% with some implementation here.

Should I do all these??? The reason is, I am getting an idea that 
the accumulator predicate has to be used.
BUT, accumulator predicate stores the intermediate results, I feel 
it should not be done.

IS IT REALLY needed to use them?? Are they the right types and 
predicates??

If yes plz do tell me how in reality it can be done. I am 
confused. Plz some code to illustrate it. A small code will do.

Thanks and Regards,

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

