Created
September 25, 2011 15:03
-
-
Save kmizu/1240691 to your computer and use it in GitHub Desktop.
Scala's type constructor is not "curried" form. In this example, it is explained that we can emulate type constructor currying using abstract type member.
This file contains 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
trait TF { | |
type Apply[A] | |
} | |
type Curry2[F[_, _]] = TF { type Apply[X] = TF { type Apply[Y] = F[X, Y] } } | |
type Curry3[F[_, _, _]] = TF { type Apply[X] = Curry2[(TF { type Apply[Y, Z] = F[X, Y, Z] })#Apply] } | |
// ... | |
type CurriedMap = Curry2[Map] | |
val x: CMap#Apply[String]#Apply[Int] = Map("x" -> 1, "y" -> 1) //It is valid code. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment