4

There exist Semigroup and Semigrupal

Semigroup[Int].combine(1, 41)                  // : Int = 42
Semigroupal[Option].product(Some(1), Some(41)) // : Option[(Int, Int)] = Some(value = (1, 41))

What is -al suffix meant to convey? In what sense does -al convey the distinction between Semigroup and Semigroupal? Similarly there is language of Monoid and Monoidal; is -al here conveying the distinction along the same lines?

Mario Galic
  • 47,285
  • 6
  • 56
  • 98

2 Answers2

4

edmundnoble states semigroupal is an abbreviation

Semigroupal is an abbreviation for semigroupal functor which is to a monoidal functor as a semigroup is to a monoid

or as hrhino puts it

"semigroupal functor" - "functor" = "semigroupal"

cats.Semigroupal points towards the concept of semigroupal functor which is defined something like

trait SemigroupalFunctor[F[_]] {
  def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
  def map[A, B](fa: F[A])(f: A => B): F[B]
}

semigroupal functor is like monoidal functor without the unit

trait MonoidalFunctor[F[_]] {
  def unit: F[Unit]
  def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
  def map[A, B](fa: F[A])(f: A => B): F[B]
}

Now cats.Semigroupal is a generalisation of semigroupal functor where only the product is extracted into its own type class

trait Semigroupal[F[_]] {
  def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
}

hence the naming stops at just Semigroupal instead of SemigroupalFunctor. The full semigroupal functor can be found in cats in the form of Apply which combines Semigroupal and Functor as shown in the following simplified view

trait Semigroupal[F[_]] {
  def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
}

trait Functor[F[_]] {
  def map[A, B](fa: F[A])(f: A => B): F[B]
}

trait Apply[F[_]] extends Semigroupal[F] with Functor[F] { 
  def ap[A, B](ff: F[A => B])(fa: F[A]): F[B]
}

Semigroupal used to be called Cartesian until rename Cartesian to Semigroupal #1961

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
1

See this paper on semigroupal categories. I don't believe a Semigroupal has to actually represent a semigroupal category, but its product operation is something semigroupal categories have as well.

Similarly there is language of Monoid and Monoidal; is -al here conveying the distinction along the same lines?

Yes, it's related in the same way (but monoidal categories seem to be much more widely used).

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • I see, according to the paper, a semigroupal category is a triple (M, ⊗, α), so `cats.Semigroupal#product` would correspond to just semigroup**al functor** ⊗? Regarding -al, is it meant to convey just that the binary operation of a category has the associativity aspect of the semigroup? – Mario Galic Jun 12 '21 at 09:27
  • Hmm doesn't the word functor indicate presence of `map`, but `cats.Semigroupal` just has `product`, so maybe the name is not a shorthand for semigroupal functor? I guess it would be more correct to call `cats.Apply` a semigroupal functor, as it extends both `Functor` and `Semigroupal`? – Mario Galic Jun 12 '21 at 10:05
  • I thought about saying something like "`Semigroupal` gestures at semigroupal categories" instead. "I guess it would be more correct to call cats.Apply a semigroupal functor, as it extends both Functor and Semigroupal?" Yes, I think so. – Alexey Romanov Jun 12 '21 at 12:36