Re: [Haskell-cafe] A home-brew iteration-alike library: some extension quiestions

Just for the record: the library IterateeM.hs, uses NO extensions to Haskell98, let alone Haskell2010. The library as written requires LowLevelIO.hs, which uses FFI (which has been Haskell98 addendum and is in proper Haskell2010). The sample code, Wc.hs, for example, is Haskell98. So, the iteratee can be written with no extensions whatsoever. In particular, IterateeM does not use any monad transformer library (although it could have). I found that the trouble of writing a state monad for a particular state is negligible compared to the pain of choosing a particular monad transformer library, and especially the pain inflicted on the users who have to deal with many a conflicts of monad transformer libraries.
The problem was that I wished Zippee. It means that external enumerator must be "suspended" at some points so Zippee can process elements from both left and right streams in desired order. It makes any other approach I considered impossible to use.
The file IterateeN.hs demonstrates zipping two streams together (in lock-step and not in-lockstep). It turns out, the existing Iteratee interface and type suffices. This is described in more detail in: Parallel composition of iteratees: one source to several sinks http://okmij.org/ftp/Streams.html#1enum2iter Parallel composition of streams: several sources to one sink http://okmij.org/ftp/Streams.html#2enum1iter

Well, It looks like with 'transformer' look onto iteratees it is possible to fold two streams without anything except Iteratee, yet some complications arise. Even real zipping. for example merging two sorted streams with output stream sorted, is expressible. More preciesely, I tried to write a separate module (attached) and with careful use of 'runners' I got stack of Iteratee/Enumeratee transformers, that shall do the job. However, typing of the running function and input streams is a mess: t \i e g -> mkEnumeration $ enumerateTo g $ mkIteration $ enumerateTo e (mkIteration i) \i e g -> mkEnumeration $ enumerateTo g $ mkIteration $ enumerateTo e (mkIteration i) :: Iteratee e2 a s2 (Iteratee e1 a s1 (Enumeratee e r s m)) a -> Enumeration e2 a s2 (Iteratee e1 a s1 (Enumeratee e r s m)) -> Enumeration e1 a s1 (Enumeratee e r s m) -> Enumeration e r s m And lifting of innermost iteratee's 'nextIM' is not sufficient for merge of sorting streams: A separate one must be written.
participants (2)
-
oleg@okmij.org
-
Permjacov Evgeniy