independant monads used together?

09 Nov 2001 23:09:25 +0100

I'm trying to achieve something like (ocaml)

let rec zipfold f init it1 it2 =
  if it1#is_end || it2#is_end then init
    let v1, v2 = it1#value, it2#value in
    it1#next ; it2#next ;
    zipfold f (f v1 v2 init) it1 it2

which is a foldl on 2 iterators. I've managed to use monads for one iterator,
but i completly miss the way to work with 2 monads. Is there really no other
solution than creating a monad over the 2 iterators??

-- using the StateTrans as in
newtype StateTrans s a = ST( s -> (s, a) )

-- can't write l == [] otherwise it need Eq on elem of lists
is_empty_list [] = True
is_empty_list _ = False

is_empty = ST(\l-> (l, is_empty_list l))
val = ST(\l -> (l, head l))
next = ST(\l -> (tail l, ()))

myfoldl f init =
    do b <- is_empty
       if b
	  then return init
	  else do e <- val
		  myfoldl f (f e init)