Skip to content
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

Revamp Semigroup doc #1442

Merged
merged 2 commits into from
Nov 16, 2016
Merged

Conversation

adelbertc
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Oct 27, 2016

Current coverage is 92.22% (diff: 100%)

Merging #1442 into master will increase coverage by 0.02%

@@             master      #1442   diff @@
==========================================
  Files           242        242          
  Lines          3615       3615          
  Methods        3546       3546          
  Messages          0          0          
  Branches         69         69          
==========================================
+ Hits           3333       3334     +1   
+ Misses          282        281     -1   
  Partials          0          0          

Powered by Codecov. Last update 25e9628...8911efb

@adelbertc adelbertc mentioned this pull request Oct 27, 2016
18 tasks
```

must be the same as
`combine` also needs to be associative, which means the following equality must hold for any choices of `x`, `y`, and
Copy link
Contributor

Choose a reason for hiding this comment

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

The flow feels odd here where it's just been declared emphatically that Semigroup is about an associative binary operation, then to immediately say that combine also needs to be associative.

Maybe something like:

where combine is the associative operation, which...

You'll notice that instead of declaring `one` as `Some(1)`, I chose
`Option(1)`, and I added an explicit type declaration for `n`. This is
because there aren't type class instances for `Some` or `None`, but for
`Option`. If we try to use `Some` and `None`, we'll get errors:
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's detail, but I'm slightly loathe to lose this bit on Some/None, as it's something which I've seen trip up a lot of people knew to type classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we're going to move these "gotchas" to a more generic location, being handled at this PR: #1404

Monoid[Int].combine(Monoid[Int].empty, x)
```

# Exploiting laws: associativity and identity
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really see how this sub-heading fits with the text under it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I had a different intent for this section initially but went with a different direction and forgot to change it, oops :-)

`empty` method to semigroup's `combine`. The `empty` method must return a
value that when combined with any other instance of that type returns the
other instance, i.e.
`Monoid` extends the power of `Semigroup` by providing an additional `empty` value.
Copy link
Contributor

Choose a reason for hiding this comment

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

This reads much more cleanly. 👍

```tut:book
import cats.syntax.semigroup._

1 |+| 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Addition always seems like a poor motivating example for this syntax to me. Maybe Option[Int] might make the case better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue I had with introducing the Option[A] Semigroup this early was there are some nuances to it with regards to how it handles None. Since the Semigroup instance is sort of incidental because it really is a Monoid instance, I opted to introduce it in the Monoid section instead.

I could perhaps show an early Map example and say details to come later in this post. As I type that out I think that's a good idea, I'll go ahead and do that.

```

Examples.
Many types that form a `Semigroup` also form a `Monoid`, such as `Int`s (with `0`) and `Strings` (with `""`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably tangential to this PR, but I've read discussions on the variations of

T:

  • has a
  • is a
  • forms a

Typeclass[T], maybe this is something nice to have a sentence about? I don't care which phrase is used though (maybe a note that they're saying the same thing), and I'm guessing somewhere on http://typelevel.org/cats/typeclasses.html would be appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I ran into this same issue too. I'll keep that in mind on my next pass through (or you can make a PR! :D ) Thanks Long!

Copy link
Contributor

Choose a reason for hiding this comment

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

@adelbertc 👍

@kailuowang
Copy link
Contributor

👍 LGTM. Definitely a big improvement from the previous version.

@adelbertc adelbertc merged commit b71a25d into typelevel:master Nov 16, 2016
@stew stew removed the in progress label Nov 16, 2016
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.

6 participants