Open Gabriella439 opened 10 years ago
I played around with this concept in a fork: b08e06b9b9bbbcccc189cf23be5c8469c40ce59c
Changing to newtype Model s a b = AsModel (Producer a (State s) () -> Producer b (State s) ())
seems to be fine, but what I couldn't work out is how to lift this sig within runMVC to the IO Monad ie
(Producer a (State s) () -> Producer b (State s) ()) -> (Producer a (StateT s IO) () -> Producer b (StateT s IO) ())
Is there a way to "fmap" hoist (hoist generalize)
to a function?
There probably isn't a way to do it with exactly that type signature. Instead, what you may have to do is change the type to:
newtype Model s a b = AsModel (forall m . Monad m => Producer a (StateT s m) () -> Producer b (StateT s m) ())
That will enforce that the function can't use the base monad (because it has to work for any m
), and then runMVC
can specialize the m
to IO
.
Getting closer but I'm finding the monad being locked away in Model
s a b problematic.
eg the type signature for asFoldM looks suspect.
7bf29d6222f8c4608eb3766b51721de8d9263772
But overall, initial testing is looking good: http://lpaste.net/111205
Note that you can implement asFold
in terms of Pipes.Prelude.scan
and asPipe
Actually, I take that back, it would work only if it did not use State
(i.e. it was a pure fold).
It would have this type:
This would allow users to take advantage of
pipes-parse
abstractions.