Skip to content

Instantly share code, notes, and snippets.

@drvink

drvink/occurs.ml Secret

Last active January 20, 2021 00:30
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 drvink/a0094680aaae2569951ea4601752944d to your computer and use it in GitHub Desktop.
Save drvink/a0094680aaae2569951ea4601752944d to your computer and use it in GitHub Desktop.
Exceptions to the OCaml occurs check without -rectypes
(** Exceptions to the occurs check without -rectypes. *)
type ski = | S | K | I
(** An equirecursive type via an object. *)
let via_object :
ski ->
< f : (< f : 'a -> (< f : 'a; .. > as 'b); .. > as 'a) -> 'b -> 'c; .. > ->
'a -> 'b -> 'c
= function
| S -> fun a b c -> (a#f c) (b#f c)
| K -> fun a b -> a#f b
| I -> fun a -> a#f
(*
let _ = via_object S
(object method f x y = 1 end)
(object method f x = object method f = x end end)
(object method f = object (self : 'obj) method f x = self#f x end end)
*)
(* - : int = 1 *)
(** A conjunctive polymorphic variant. *)
let via_polyvariant :
ski ->
[< `f of
'a -> 'b -> 'c &
'd -> ([< `f of 'a ] as 'e) -> 'c &
([< `f of 'a -> 'b & 'd ] as 'f) -> 'e -> 'c ] ->
'f -> 'e -> 'c
= function
| S -> fun (`f a) (`f b) (`f c) -> (a c) (b c)
| K -> fun (`f a) (`f b) -> a b
| I -> fun (`f a) -> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment