8

Heiko Seeberger wrote a great blog post on category theory here:

https://hseeberger.wordpress.com/2010/11/25/introduction-to-category-theory-in-scala/

In it, he defines a GenericFunctor like so:

trait GenericFunctor[->>[_, _], ->>>[_, _], F[_]] {
  def fmap[A, B](f: A ->> B): F[A] ->>> F[B]
}

I did not have any luck finding documentation references to the ->> and ->>> symbols in documentation. Could someone please explain what they are doing?

jxstanford
  • 3,339
  • 3
  • 27
  • 39

3 Answers3

14

The symbols themselves don't mean anything. They are arbitrary names Heiko picked:

> class Foo[A, B]
defined class Foo

> class Foo[M1[_], M2[_]]
defined class Foo

> class GenericFunctor[->>[_, _], ->>>[_, _], F[_]]
defined class GenericFunctor

They are parts of type parameters that they themselves are type constructors (higher-kinded types if you want to sound fancy). Type applications can be written infix, so A ->> B is same as ->>[A, B].

As per what's going on... Heiko says

Looking at the ingredients, we find all that we need: Types A and B are mapped to types F[A] and F[B] and maps A ->> B are mapped to maps F[A] ->>> F[B].

Since we are talking category theory, we want to avoid the term function because that's implementation specific, but we want to describe something kind of like a function. Something-like-a-function in their lingo is an arrow. We need two of them since we don't want to assume the incoming and outgoing arrows to be the same. These two arrows are represented by ->> and ->>>. F[_] is a container like List and Option. I think..

So fmap (aka map method in Scala) takes an arrow of values and returns another arrow of containers. Except unlike map method, fmap returns an arrow that takes a container.

A specific application of the GenericFunctor using Function for both arrows is Functor. And specific application of Functor that uses List for the container is ListFunctor.

object ListFunctor extends Functor[List] {
  def fmap[A, B](f: A => B): List[A] => List[B] = as => as map f
}

So that's taking a function from A to B, and returning a function from List[A] to List[B], calling map internally.

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
5

A clue is that they are within square brackets in the trait definition: they are just arbitrary symbols that have been picked by the blog author, just as [T] is often chosen for generic classes, traits, and methods. These here just happen to be higher-kinded types (i.e. parameters with parameters).

The arrow-like name was chosen because, as he says,

"A ->> B is just another way to write ->>[A, B], which nicely reflects the fact that we are talking about maps here."

Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
1

Answer copied from my answer to a duplicate question on request:

It's a higher-kinded type, described nicely in this introduction and in this research paper.

The reason you might find it confusing is that ->> is the name for the higher-kinded type -- it might have as well been called Arrow instead.

Community
  • 1
  • 1
axel22
  • 32,045
  • 9
  • 125
  • 137