Skip to content

Instantly share code, notes, and snippets.

@Octachron
Created March 3, 2018 17:34
Show Gist options
  • Save Octachron/7fdc1dd42c0e9af67a6e1baf0fa25c16 to your computer and use it in GitHub Desktop.
Save Octachron/7fdc1dd42c0e9af67a6e1baf0fa25c16 to your computer and use it in GitHub Desktop.
module X: sig
type +'a t
val one: [`one of _ ] t
val two: [`two of _ ] t
val match':
[< `one of 'r & 'a | `two of 'r & 'b] t -> 'a -> 'b -> 'r
end = struct
type 'a t = One | Two
let one = One
let two = Two
let match' value branch_1 branch_2 =
match value with
| One -> Obj.magic branch_1
| Two -> Obj.magic branch_2
end
open X
let f x = match' x 1 1.
let g x y =
f x + f y
let x = f one + 1
let y = f two +. 1.
let () = Format.printf "Test:%d %f %d@." (f one) (f two) (g one one)
(* error
;; f two + 1
;; f one +. 1
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment