Skip to content

Instantly share code, notes, and snippets.

@j0sh
Last active November 3, 2015 19:58
Show Gist options
  • Select an option

  • Save j0sh/de6f84ed6ed42a6bc6cf to your computer and use it in GitHub Desktop.

Select an option

Save j0sh/de6f84ed6ed42a6bc6cf to your computer and use it in GitHub Desktop.
gadt in 'guard' like pattern branch
File "test.ml", line 17, characters 13-32:
Error: This pattern matches values of type int prim expr
but a pattern was expected which matches values of type a#0 expr
Type int prim is not compatible with type a#0
type _ prim =
| TS : string -> int64 prim
| Str : string -> string prim
| Int : string -> int prim
type _ expr =
| Val : 'a prim -> 'a prim expr
| Expr : string * 'a expr * 'b expr -> 'c expr
let rec all : type x . x prim -> string = function
| TS s -> s
| Str s -> s
| Int s -> s
let rec expr : type x . x expr -> string = function
| Val x -> all x
| Expr (s, (y : int prim expr), z) -> "guarded"
| Expr (s, y, z) -> Printf.sprintf "%s -- %s -- %s" s (expr y) (expr z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment