Skip to content

Add execWriterT #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 16, 2014
Merged

Add execWriterT #23

merged 2 commits into from
Dec 16, 2014

Conversation

MichaelXavier
Copy link
Contributor

No description provided.

@@ -13,6 +13,9 @@ newtype WriterT w m a = WriterT (m (Tuple a w))
runWriterT :: forall w m a. WriterT w m a -> m (Tuple a w)
runWriterT (WriterT x) = x

execWriterT :: forall w m a. (Monad m) => WriterT w m a -> m w
execWriterT m = runWriterT m >>= \(Tuple _ w) -> return w
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just snd <$> runWriterT m which only needs an Apply constraint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny, I actually originally committed it with Apply and <$>, but I looked at existing code and saw that it used Monad so I decided to stick with convention. Given this information, should I go with Apply, and additionally would you like the following code updated to use Apply as well?

https://github.com/purescript/purescript-transformers/blob/master/src/Control/Monad/State/Trans.purs#L16

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I'm in favour of using the most general type signatures we can. A lot of this was ported from Haskell, I think, so it can definitely be refined with our new hierarchy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it would only need Functor right? But couldn't we eschew the constraint entirely with pattern matching? Or is there some law which makes the constraint necessary?

@MichaelXavier
Copy link
Contributor Author

Sorry about the delay. Let me know what you think of these updates.

@garyb
Copy link
Member

garyb commented Dec 16, 2014

👍

paf31 added a commit that referenced this pull request Dec 16, 2014
@paf31 paf31 merged commit 79fad83 into purescript:master Dec 16, 2014
@MichaelXavier MichaelXavier deleted the writer-misc branch February 13, 2015 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants