solution that works in 3.11 but fails in 3.10.2
[sqlgg.git] / poly.ml
blob90721103562a5b8a1dd0e9b4a52d169c99b41f10
1 type t = [`A of int | `B of string | `Z of t]
3 let rec use_t = function
4 | `A i -> i
5 | `B s -> String.length s
6 | `Z x -> use_t x
8 let rec show_t
9 : t -> unit (* comment this *)
10 = function
11 | `A i -> print_endline "A"
12 | `B s -> print_endline "B"
13 | `Z x -> (print_string "Z"; show_t x)
15 let rec make_narrow = function
16 | `A i -> `A i
17 | `B s -> `A (String.length s)
18 | `Z x -> `Z (make_narrow x)
20 let rec use_narrow = function
21 | `A i -> i
22 | `Z x -> (use_narrow x)
24 let tee f x = f x; x
26 let final x =
27 let y = make_narrow x in
28 show_t y;
29 use_narrow y
31 let final x = use_narrow (make_narrow (tee show_t x))
33 let final x =
34 use_narrow (tee (fun (z:[`A of int| `Z of 'a] as 'a) -> show_t (z:>t)) (make_narrow x))