-
-
Save Kakadu/2a7d9f483103a7c7ed7b0af186d22455 to your computer and use it in GitHub Desktop.
Typedtree and GADT
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
module _ = struct | |
(* OCaml 3.12.1 *) | |
open Typedtree | |
type ttt = { self : 'a . 'a pattern_desc pattern_data -> bool} | |
let _hack = | |
let helper (type a) | |
(self : ttt) | |
(p1: a Typedtree.pattern_desc pattern_data) = | |
match p1.pat_desc with | |
| Tpat_any | |
| Tpat_var _ -> true | |
| Tpat_constant c1 -> true | |
| Tpat_tuple t1 -> List.for_all self.self t1 | |
| Tpat_construct (_, cd1, a1) -> List.for_all self.self a1 | |
| Tpat_value v1 -> | |
self.self | |
(v1 :> value Typedtree.pattern_desc Typedtree.pattern_data) | |
| Tpat_exception _ | |
| _ -> false | |
in | |
let rec ans = { self = (fun eta -> helper ans eta) } in | |
ans | |
let _hack_bad = | |
let helper (type a) | |
(self : a pattern_desc pattern_data -> bool) | |
(p1: a Typedtree.pattern_desc pattern_data) = | |
match p1.pat_desc with | |
| Tpat_any | |
| Tpat_var _ -> true | |
| Tpat_constant c1 -> true | |
| Tpat_tuple t1 -> List.for_all self t1 | |
| Tpat_construct (_, cd1, a1) -> List.for_all self a1 | |
| Tpat_value v1 -> | |
self | |
(v1 :> value Typedtree.pattern_desc Typedtree.pattern_data) | |
(* | |
Error: This expression has type value Typedtree.pattern_desc pattern_data | |
but an expression was expected of type | |
a Typedtree.pattern_desc pattern_data | |
Type value is not compatible with type a | |
*) | |
| Tpat_exception _ | |
| _ -> false | |
in | |
let rec ans eta = helper ans eta in | |
ans | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment