[mercury-users] map__foldl2

Dominique de Waleffe ddw at miscrit.be
Tue Dec 14 20:10:38 AEDT 1999

> Note the available modes of `map__foldl':
> :- mode map__foldl(pred(in, in, in, out) is det, in, in, out) is det.
> :- mode map__foldl(pred(in, in, in, out) is semidet, in, in, out)
> is semidet.
> :- mode map__foldl(pred(in, in, di, uo) is det, in, di, uo) is det.
> This means the 3rd and 4th arguments of the predicate you pass
> must either
> have modes `di' and `uo', or `in' and `out'.  Unfortunately, your
> `indi' and
> `outuo' do not match either of these.

Right. Clearly that's not what the compiler tells me...

> What's the other argument pair going to be in your application?  Is the
> initial input likely to be small, or big and complicated?  If
> it's going to
> be small (e.g. an empty list, an integer, etc.) then it's
> probably not going
> to hurt you much to make it unique (using `copy/2' if necessary).

The first accumulator is some state of the application. The second is the
infamous io__state.

> I also thought this looked a bit strange:
> > :- inst inst1 = bound(ground-unique ; ground-ground).
> I don't think this means what you intend it to mean.  Do you really mean
> that either of these are allowed, or are you trying to
> (effectively) get the
> higher-order predicate to work in multiple modes?

I am not sure either that those declarations mean what I wanted them too.
This is one of the parts of Mercury which seems far too complicated for
'normal users'.

> Unfortunately, it seems one cannot do this kind of wrapping trick with
> higher-order predicates if you want the result to work in
> multiple modes.
> :-(

Sorry, but I would not call this a 'trick'. If I could do that kind of high
level wrapping easily, I could go a lot faster in writing applications.

Thus the implication seems to be that I should go down to tree234, extend
the folding preds there, then do the same in map. Is that right or is there
a other easy 5 lines solutions?

Meanwhile I got a work around getting stuff into  a list  then use
list__foldl2... That's a trick I should not have to use.


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