Skip to content

Instantly share code, notes, and snippets.

@nbenns
Created April 24, 2018 17:07
Show Gist options
  • Save nbenns/f1f3a448fd51b7a4b6eee66f0c1da9d2 to your computer and use it in GitHub Desktop.
Save nbenns/f1f3a448fd51b7a4b6eee66f0c1da9d2 to your computer and use it in GitHub Desktop.
// 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