Gabriella439 / Haskell-MVC-Library

Model-view-controller
BSD 3-Clause "New" or "Revised" License
62 stars 20 forks source link

Add `asGetter` #12

Open Gabriella439 opened 10 years ago

Gabriella439 commented 10 years ago

It would have this type:

asGetter :: (Producer a (State s) () -> Producer b (State s) ()) -> Model s a b

This would allow users to take advantage of pipes-parse abstractions.

tonyday567 commented 9 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?

Gabriella439 commented 9 years ago

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.

tonyday567 commented 9 years ago

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

Gabriella439 commented 9 years ago

Note that you can implement asFold in terms of Pipes.Prelude.scan and asPipe

Gabriella439 commented 9 years ago

Actually, I take that back, it would work only if it did not use State (i.e. it was a pure fold).