Skip to content

Instantly share code, notes, and snippets.

@derrickturk
Created March 11, 2021 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derrickturk/24cad2f13fdcd0ea86caf0dae68122b6 to your computer and use it in GitHub Desktop.
Save derrickturk/24cad2f13fdcd0ea86caf0dae68122b6 to your computer and use it in GitHub Desktop.
working around the lack of rank-2 types in OCaml
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