Skip to content

Instantly share code, notes, and snippets.

@Gbury

Gbury/gadt.ml Secret

Created September 18, 2020 17:48
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 Gbury/0a2f8d88f58d5424ea4b4b1aca35c287 to your computer and use it in GitHub Desktop.
Save Gbury/0a2f8d88f58d5424ea4b4b1aca35c287 to your computer and use it in GitHub Desktop.
type _ t =
| Bar : 'a -> 'a t
| Foo : 'a list t -> 'a t
let rec f : type a. a t -> a = function
| Bar y -> y
| Foo y ->
begin match f y with
| [] -> assert false
| h :: r -> h
end
let rec f (type a) (x: a t) : a =
match x with
| Bar y -> y
| Foo y ->
begin match f y with
| [] -> assert false
| h :: r -> h
end
(*
File "gadt.ml", line 17, characters 18-19:
10 | begin match f y with
^
Error: This expression has type a list t
but an expression was expected of type 'a
The type constructor a would escape its scope
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment