The K in SemigroupK
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
The Scaladoc on SemigroupK (https://github.com/typelevel/cats/blob/v0.7.2/core/src/main/scala/cats/SemigroupK.scala) says:
* SemigroupK is a universal semigroup which operates on kinds.
*
* This type class is useful when its type parameter F[_] has a
* structure that can be combined for any particular type. Thus,
* SemigroupK is like a Semigroup for kinds (i.e. parameterized
* types).
function as first-order values
I think there's a misunderstanding of the terms. The oft repeated analogy, "kind is to a type, as type is to a value" probably isn't going to clarify it either, but it's a start. Consider the following:
scala> (_: Int) + 1
res0: Int => Int = <function1>
In fp, we can consider functions to be a value, and in Scala, we can store it in a variable:
scala> val f = (_: Int) + 1
f: Int => Int = <function1>
If we pass in some Int, we can derive a proper value e.g. 2. Because Int => Int is one order away from the proper value, it's also called a first-order value. (A function that accepts Int => Int and returns Int would be a higher-order value, but it doesn't matter here) The important point is that f is a value, not a type.
type constructor as first-order types
Next, let's consider the type equivalent of the Int => Int, which is Option:
scala> :k -v Option
scala.Option's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.
Option accepts a single parameter A to become a proper type. Just as we considered f to be a value, we consider Option to be a type. It's just first-order kinded.
Parameterized types can be called "type constructors" or "type functions", but they themselves are not "kinds."
Semigroup which operates on types
A semigroup that operates on types would be something like a type constructor =>[_, _], since you can take type A and type B and construct A => B.
Semigroup which operates on kinds
Using the standard notation, the values for kinds are combination of *, -> and parenthesis. So, the semigroup that operates on kinds would be something along the lines of _ -> _, where you pass in kind A and kind B and construct A -> B. This is clearly not what SemigroupK is doing.
SemigroupF?
I'm not sure what a good alternative would be but I hope I was able to demonstrate that neither "type level" nor "kind level" is appropriate. Maybe we can call it SemigroupF for type constructors that take a single operator.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with core/src/main/scala/cats/SemigroupK.scala at the Scaladoc quoted in the issue, then read the discussion about kinds, types, and the proposed SemigroupF terminology. The issue has no settled wording or concrete edit; completion would require agreement on the terminology and an updated Scaladoc that reflects it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100