-
-
Save drvink/a0094680aaae2569951ea4601752944d to your computer and use it in GitHub Desktop.
Exceptions to the OCaml occurs check without -rectypes
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
(** 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