Skip to content

Instantly share code, notes, and snippets.

@Octachron
Created August 18, 2023 12:07
Show Gist options
  • Save Octachron/f813cce9d11b19062fb3c3b8e6321869 to your computer and use it in GitHub Desktop.
Save Octachron/f813cce9d11b19062fb3c3b8e6321869 to your computer and use it in GitHub Desktop.
Contravariance and type equations
module type pair = sig type a type b end
module type S = functor (Pair:sig include pair type b = a end) -> sig
open Pair
type either = Left of a | Right of b
end
module R = struct
type a = A
type b = a
end
module F(Make: S) = struct
module Mk = Make
module E = Mk(R)
let r = E.[Left A; Right A ]
end
module Pair(X:pair) = struct
open X
type either = Left of a | Right of b
end
module Ok = F(Pair)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment