Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igstan/a7498b5fcb82a72e8a10fdb505836d02 to your computer and use it in GitHub Desktop.
Save igstan/a7498b5fcb82a72e8a10fdb505836d02 to your computer and use it in GitHub Desktop.
Kind-polymorphic Any and Nothing
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