[mercury-users] io__foldl

Ralph Becket rafe at cs.mu.OZ.AU
Sat Nov 16 12:04:47 AEDT 2002


There is no io__foldl.

Noel  Pinto, Friday, 15 November 2002:
> 
> Closure is said to be an accumulator predicate which means that it 
> stores the intermediate results.

Predicates do not store anything.  They are side-effect free
computations.

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

These are deep waters.  As Nancy suggests, start by trying to write
programs to solve simple problems without using higher order code; for
example:

- count the number of times the letter `a' appears in a list(char);
- count the number of times a digit appears in a list(char);
- compute the reversal of a list;
- compute the sublist consisting of only the non-negative members of a
  list(int);
- compute the sublist consisting of only every other member of a list.

Once you've done this, you should have enough experience to see common
patterns in the code you write, at which point any explanation we give
for how to use higher order techniques (e.g. using foldl) to solve these
problems easily will make more sense to you.

> 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??

You're putting the cart before the horse.  You should ask
- can I use foldl to solve problem X?
- How do I do so?

What you wrote above is just wild guessing - we have as little idea of
what you want to achieve as you have.  You need to present questions in
terms of concrete, concisely and well defined problems.

- 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
--------------------------------------------------------------------------



More information about the users mailing list