Open treeowl opened 7 years ago
I like this idea. Although, it does require rewriting a bunch of other functions in terms of hostMapsBind
. In my own code, I often end up with chains of Streaming.Prelude.mapM
, which I believe should be able to fuse together. It's hard to know if hoistMapsBind
is the best choice though.
Has anyone tried generalizing the streams in Data.Vector.Fusion.Stream.Monadic
?
data Stream f m r where
Stream :: (s -> StreamF s f m r) -> s -> Stream f m r
data StreamF s f m r =
Step (f s)
| Effect (m s)
| Return r
I really don't have time to look into that this week, but it might be worth thinking about. I suspect the overly weak constraint on hoist
could be troublesome, but that's mmorph
's fault.
Nope, that doesn't work, because it doesn't give a way to change the s
type mid-stream. The Monad
instance seems impossible. There might be some other way....
Huh... Actually, using the same approach vector
applies to ++
actually does seem to work. But only, of course, if there's enough inlining. It would probably still be worth some benchmarking.
I certainly don't know which ones we want, but it would be nice to get some sort of fusion. Here's one possibility to consider:
The
hoist
,maps
, and>>=
operations can be combined into a single operationIf we so desire, we can rewrite applications of
hoist
,maps
, and>>=
to applications ofhoistMapsBind
, and then fuse them using the following rule:But of course there could be much more general fusion opportunities we should be considering instead. I am especially curious about whether there's any way to convince GHC to do some of the heavy lifting itself.