Created
March 11, 2021 22:00
-
-
Save derrickturk/24cad2f13fdcd0ea86caf0dae68122b6 to your computer and use it in GitHub Desktop.
working around the lack of rank-2 types in OCaml
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
type poly_fn = { f : 'a. 'a -> 'a } | |
let ap_poly : poly_fn -> int -> bool -> int * bool = fun pf x y -> | |
(pf.f x, pf.f y) | |
let ap_poly_obj (obj: <f: 'a. 'a -> 'a>) x y = (obj#f x, obj#f y) | |
let id x = x | |
let (x, y) = ap_poly { f = id } 3 true | |
let (x2, y2) = ap_poly_obj (object method f : 'a. 'a -> 'a = id end) 3 true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment