Created
April 24, 2018 17:07
-
-
Save nbenns/f1f3a448fd51b7a4b6eee66f0c1da9d2 to your computer and use it in GitHub Desktop.
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
// From http://milessabin.com/blog/2011/06/09/scala-union-types-curry-howard/ | |
type ∧[A, B] = A with B | |
type ¬[A] = A => Nothing | |
type ¬¬[A] = ¬[¬[A]] | |
type ∨[A, B] = ¬[¬[A] ∧ ¬[B]] // De Morgan equivalence | |
type <|[X, T] = ¬¬[X] <:< T // lift and check subtype | |
def size[T: ? <| (Int ∨ String)](t: T): Int = | |
t match { | |
case i: Int => i | |
case s: String => s.length | |
} | |
size("meow") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment