Forked from szeiger/gist:3a2e7e65b641bac9764a9c02de233ab9
Last active
May 16, 2018 13:59
-
-
Save igstan/a7498b5fcb82a72e8a10fdb505836d02 to your computer and use it in GitHub Desktop.
Kind-polymorphic Any and Nothing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import scala.language.higherKinds | |
import scala.language.higherKinds | |
scala> def f[C[_], E]: List[C[E]] = Nil | |
f: [C[_], E]=> List[C[E]] | |
scala> f[List, Int] | |
res0: List[List[Int]] = List() | |
scala> f[Any, Int] | |
res1: List[Any] = List() | |
scala> f[Nothing, Int] | |
res2: List[Nothing] = List() | |
scala> f[Int, Int] | |
<console>:14: error: Int takes no type parameters, expected: one | |
f[Int, Int] | |
^ | |
scala> :kind -v List | |
List's kind is F[+A] | |
* -(+)-> * | |
This is a type constructor: a 1st-order-kinded type. | |
scala> :kind -v Any | |
Any's kind is A | |
* | |
This is a proper type. | |
scala> :kind -v Nothing | |
Nothing's kind is A | |
* | |
This is a proper type. | |
scala> :kind -v Int | |
Int's kind is A | |
* | |
This is a proper type. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment