I’m trying to wrap my head around the enumerator library and ran into a situation where I want to build a new Enumeratee in terms of two existing Enumeratees. Let’s say I have the enumeratees:
e1 :: Enumeratee x y m b
e2 :: Enumeratee y z m b
I feel that I should be able to combine them into one enumeratee
e3 :: Enumeratee x z m b
but I couldn’t find an existing function to do this in the package. I tried to write such a function myself, but my understanding of iteratees is still so limited that I couldn’t figure out a way to get all the complex types to match.
Did I just miss some basic combinator, or are Enumeratees even supposed to be composable with each other?
In theory they are composable, but the types are a bit tricky. The difficulty is that the final parameter
bof the first enumeratee isn’t actuallyb; it’s another iteratee!. Here’s the type of the><>operator from iteratee, which composes enumeratees:Note the extra
forallin the first enumeratee; this indicates that a Rank-2 type is at work. If theenumeratorauthor wants to maintain H98 compatibility (I believe this was one of the original goals), this approach is unavailable.It is possible to write this type signature in a form which doesn’t require Rank-2 types, but it’s either longer, not clear from the type that it’s actually two enumeratee’s that are being composed, or both. For example, this is ghc’s inferred type for
(><>):Although these types are for
iterateecombinators, hopefully it’s enough information you’ll be able to apply them toenumerator.