Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala ~> (tilde greater than) operator

I have the following scala class definition (found in a paper), modeling categories:

trait Category[~>[_, _]] {     def compose[A, B, C]      (f: B ~> C)      (g: A ~> B)      : A ~> C     def id[A]: A ~> A } 

can someone explain me what the '~>' means in the Category type parameter, and in the methods return type? Or direct me to a resource that explains it... I'm new to Scala (coming from Java), so forgive me if that's something a scala user should have known... Thank you in advance

like image 979
Andrea Avatar asked Apr 10 '12 09:04

Andrea


People also ask

What does ~> mean in Scala?

~> is just the placeholder-name for the type-parameter of Category . Like the T in class Option[T] . Additionally, Scala syntax allows you to write B ~> C as a shorthand for ~>[B, C] .

What does =!= Mean in Scala?

It has no special meaning whatsoever. It is also not a well-known method name in Scala. It seems to come from some library; you need to look at the documentation of whatever library you are using to figure out what it does.

What is the meaning of ~>?

In other words: ~> means it will only allow that specific version, and newer sub-versions in the last decimal.

Can you do += in Scala?

There are no ++ or -- operators in Scala (use += or -=) Second, Scala encourages the use of immutable values, and with immutable values you'll have no need for these operators.


1 Answers

~> is just the placeholder-name for the type-parameter of Category. Like the T in class Option[T].

Additionally, Scala syntax allows you to write B ~> C as a shorthand for ~>[B, C].

Maybe things get clearer, if you rename it:

trait Category[Mapping[_, _]] {   def compose[A, B, C](f: Mapping[B, C])(g: Mapping[A, B]): Mapping[A, C]   def id[A]: Mapping[A, A] } 
like image 151
Debilski Avatar answered Sep 24 '22 13:09

Debilski