Skip to content

Add Extend and Semigroup instances. #5

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 1 commit into from
Sep 2, 2014
Merged

Conversation

joneshf
Copy link
Member

@joneshf joneshf commented Sep 2, 2014

No description provided.

garyb added a commit that referenced this pull request Sep 2, 2014
Add `Extend` and `Semigroup` instances.
@garyb garyb merged commit d3d1296 into purescript:master Sep 2, 2014
@garyb
Copy link
Member

garyb commented Sep 2, 2014

Nice, thanks.

@paf31
Copy link
Contributor

paf31 commented Sep 2, 2014

Is this the only way of extending a Semigroup? Seems like this would also be valid:

instance semigroupMaybe :: (Semigroup a) => Semigroup (Maybe a) where
  (<>) (Just x) (Just y) = Just (x <> y)
  (<>) _ _ = Nothing

Seems like your case is already handled by First in purescript-monoids.

Also, just for my own curiosity, what is the Extend instance used for?

@paf31
Copy link
Contributor

paf31 commented Sep 2, 2014

Sorry, ignore the part about First. Obviously incorrect.

Still, does it make sense to newtype this?

@garyb
Copy link
Member

garyb commented Sep 2, 2014

The version I just merged is the way Haskell implements Monoid Maybe, so I figure it's right.

Extend is the superclass of Comonad, it's bind with the arrows reversed.

@paf31
Copy link
Contributor

paf31 commented Sep 2, 2014

I was just wondering what it's used for. I mean, I know what the Maybe monad is used for, but Maybe isn't a Comonad, so I don't see an obvious meaning of the Extend instance. Trying to interpret it in terms of tree redecoration but having trouble.

@paf31
Copy link
Contributor

paf31 commented Sep 2, 2014

Why not just (<<=) f x = Just $ f x for example? Does that violate one of the laws?

@garyb
Copy link
Member

garyb commented Sep 2, 2014

Ah, I see what you mean. @joneshf?

@joneshf
Copy link
Member Author

joneshf commented Sep 3, 2014

Right, I think they're both lawful instances and it comes down to semantics. Though, one instance might play nicer with CoFree whereas the other might not. Not entirely sure there.

I think short cutting the Nothing keeps the semantics of it being optional. Always passing it to the function means we'd have to join . If we try to duplicate Nothing, it seems sensible we get Nothing. Maybe it makes more sense to duplicate Nothing and get Just Nothing. Maybe since they're both lawful, we should newtype them and call it a day.

Thoughts?

@paf31
Copy link
Contributor

paf31 commented Sep 3, 2014

I don't mind about Extend, I was just curious more than anything else. Let's wait and see if anyone has any comments I guess.

@joneshf
Copy link
Member Author

joneshf commented Sep 3, 2014

Sounds good to me.

Honestly, I don't have an immediate use for this. I just saw it could be done, so I made a PR :D

@garyb
Copy link
Member

garyb commented Sep 3, 2014

Should I do a release of this with Extend as it is then? Since it's already merged...

@paf31
Copy link
Contributor

paf31 commented Sep 3, 2014

Sounds good to me.

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.

3 participants