Skip to content

Instantly share code, notes, and snippets.

@robsimmons
Created November 13, 2011 20:31
Show Gist options
  • Save robsimmons/1362633 to your computer and use it in GitHub Desktop.
Save robsimmons/1362633 to your computer and use it in GitHub Desktop.
Contravariance
datatype foo = A | B | C | D
(*[ datasort ab = A | B ]*)
(*[ datasort bc = B | C ]*)
(*[ datasort abc = A | B | C ]*)
(* This works *)
(*[ val x: ab & bc ]*)
val x = B
(* This, however, does not...
(*[ val y: ab & bc ]*)
val y = A
*)
(* Intuition: ab \/ bc = abc *)
(*[ val f: (ab -> ab) & (bc -> bc) ]*)
fun f A = A
| f B = B
| f C = C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment