Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRemove usage of `Free` #8
Conversation
thomashoneyman
added some commits
Jun 25, 2018
This comment has been minimized.
This comment has been minimized.
|
Side note: this does not have updated docs, which I can go back and add in. I left that out until I'm sure this is the approach y'all like! |
thomashoneyman
referenced this pull request
Jun 25, 2018
Closed
Create a branch that doesn't use Free at all #6
This comment has been minimized.
This comment has been minimized.
natefaubion
commented
Jun 25, 2018
|
The compiler somewhat annoyingly does not allow type synonyms in instance heads. You can get around it with a import Type.Equality as TE
type Environment = { ... }
instance monadAskExampleM :: TE.TypeEquals Environment e => MonadAsk e ExampleM where
ask = ExampleM (asks TE.from)In these examples, hardcoding |
This comment has been minimized.
This comment has been minimized.
natefaubion
commented
Jun 25, 2018
|
Likewise, in the old examples, the classes are unnecessary because you are using an initial encoding (Free) to swap out different interpreters. |
thomashoneyman
added some commits
Jun 26, 2018
thomashoneyman
reviewed
Jun 26, 2018
| env <- ask | ||
| liftEffect $ do | ||
| st <- TE.from <$> Ref.read env.state | ||
| Ref.write (TE.to $ f st) env.state |
This comment has been minimized.
This comment has been minimized.
thomashoneyman
Jun 26, 2018
Contributor
This bit is a little gross -- I'd prefer to use modify_ -- but couldn't figure out the necessary type coercion.
This comment has been minimized.
This comment has been minimized.
natefaubion
Jun 26, 2018
As you've found out, TypeEquals can be very difficult to work with for anything non-trivial. Maybe a newtype is better? You can always export a version that unwraps it. I've done that in the past, and called it expose.
I think in this particular case it would be modify_ (TE.from >>> f >>> TE.to) env.state.
This comment has been minimized.
This comment has been minimized.
thomashoneyman
Jun 27, 2018
Contributor
I do prefer the type synonym version because it allows people to preserve the way they already tend to write these functions:
env <- ask
st <- getStateThose seem better than...
env <- unwrap <$> ask
env <- expose
st <- unwrap <$> getStatesimply because it allows you to stick with patterns you're already used to.
thomashoneyman
reviewed
Jun 26, 2018
|
|
||
| let router' = H.hoist (runExample environment state event.push token) R.component | ||
| let router' = H.hoist (flip runExampleM environment) R.component |
This comment has been minimized.
This comment has been minimized.
thomashoneyman
Jun 26, 2018
Contributor
@natefaubion I'm assuming this is the point at which you'd swap in your Test monad with its appropriate instances?
If so...
@vladciobanu perhaps it would be useful for this repository to have both an AppM and a TestM so we could demonstrate why you might want to take this approach. Let me know if you're interested!
This comment has been minimized.
This comment has been minimized.
|
Extra notes are above, but I took @natefaubion's advice and used I also made all components polymorphic over some Still haven't updated the docs, as I'm waiting to finish code first. |
This comment has been minimized.
This comment has been minimized.
|
I was hoping I'd get some time to look into this today, but I was unable to so far. I should have more time tomorrow. I really appreciate you taking your time for this PR, thank you. |
This comment has been minimized.
This comment has been minimized.
|
Finally had a chance to go over it. It looks really good to me, and I love the fact that we're finally able to write components that no longer depend on I think all that remains is docs. My plan would be to merge this as-is and I could update the docs (README and comments) this weekend or early next week, unless you're already in the process of doing so. |
This comment has been minimized.
This comment has been minimized.
|
Sure, we could do that. I haven't written any docs. One other thing that I didn't do here, but which might be useful to folks, is to add a Parallel instance for the monad so you can do...parallel things with it. If you don't think that'd be too much I can add it; if that'll just make this even more complex than it is for a beginner to check out, then we could leave it off and just merge this. |
This comment has been minimized.
This comment has been minimized.
|
I think I would like to merge this as is. I have not looked at Parallel yet, but that sounds quite interesting. Would you mind opening an issue with a very basic outline of the idea? I'd love to check it out this weekend. |
thomashoneyman commentedJun 25, 2018
@vladciobanu @natefaubion
This PR updates the repo without using
Freeanymore. In testing it appears to function the same.The only places that changed non-trivially are in
MainandControl.Monad.Example. Take a look at those two files. A brief summary of important changesnavigate,showDialog, etc.)Otherwise this is pretty much the same thing as the original version.