scala_school | Lessons in the Fundamentals of Scala | Learning library
kandi X-RAY | scala_school Summary
kandi X-RAY | scala_school Summary
This is Scala School - a set of lessons covering the Scala programming language.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of scala_school
scala_school Key Features
scala_school Examples and Code Snippets
Community Discussions
Trending Discussions on scala_school
QUESTION
I am going through Higher-kinded types & ad-hoc polymorphism section of twitter's Scala School and I don't understand and can't find reference anywhere to a unary type. Here is the context of the usage:
...For example, whereas “unary types” have constructors like
List[A]
, meaning we have to satisfy one “level” of type variables in order to produce a concrete types (just like an uncurried function needs to be supplied by only one argument list to be invoked), a higher-kinded type
ANSWER
Answered 2017-Mar-23 at 17:32Unary is another way of saying "of arity one". A one parameter function is said to be unary, whereas a two parameters function is binary, three is ternary and so forth...
The same principle applies to types. List[A]
or Set[A]
, for example, takes one type A
to form a new proper type, whereas Map[A, B]
takes two and is said to be a binary type constructor.
On a side note, types which abstract over a type constructor are called higher kinded types (e.g : Monad[F[_]]
)
QUESTION
Referring to the following tutorial https://twitter.github.io/scala_school/type-basics.html, foo[A,B]
will not compile because it is 'too generic'. I do not understand what 'too generic' implies. Why does foo
doesn't compile but foo1
does?
ANSWER
Answered 2017-Dec-08 at 10:05The type of f
is A => List[A]
. This means that f
can only be called with an argument of type A
. Therefore b
must be of type A
for f(b)
. b: B
is too generic in the sense that you allow b
to be of any type, not just A
.
Consider for example the following function:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install scala_school
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page