Created
June 9, 2020 04:50
-
-
Save szoio/23caa238b03929750c28865728f6524e to your computer and use it in GitHub Desktop.
Dependent Types
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 DependentValue{ | |
type V | |
val value: V | |
} | |
//object DependentValue { | |
// def apply[A](a: A): DependentValue { type V = A } = new DependentValue { | |
// type V = A | |
// val value = a | |
// } | |
//} | |
object DependentValue { | |
trait Aux[A] extends DependentValue { type V = A } | |
def apply[A](a: A): DependentValue.Aux[A] = new Aux[A] { | |
val value = a | |
} | |
} | |
def magic(input: DependentValue): DependentValue = input.value | |
val dep1: DependentValue.Aux[Int] = DependentValue(1) | |
val depTwo = DependentValue("two") | |
val intReturnValue: Int = magic(dep1) | |
val stringReturnValue: String = magic(depTwo) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment