Created
March 3, 2018 17:34
-
-
Save Octachron/7fdc1dd42c0e9af67a6e1baf0fa25c16 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
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