File: named_existentials.ml.ref

package info (click to toggle)
ocamlformat 0.28.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,436 kB
  • sloc: ml: 63,321; pascal: 4,769; lisp: 229; sh: 217; makefile: 121
file content (26 lines) | stat: -rw-r--r-- 709 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let ok1 = function Dyn (type a) ((w, x) : a ty * a) -> ignore (x : a)

let ok2 = function Dyn (type a) ((w, x) : _ * a) -> ignore (x : a)

type u = C : 'a * ('a -> 'b list) -> u

let f = function C (type a b) ((x, f) : _ * (a -> b list)) -> ignore (x : a)

(* with GADT unification *)
type _ expr =
  | Int : int -> int expr
  | Add : (int -> int -> int) expr
  | App : ('a -> 'b) expr * 'a expr -> 'b expr

let rec eval : type t. t expr -> t = function
  | Int n ->
      n
  | Add ->
      ( + )
  | App (type a) ((f, x) : _ * a expr) ->
      eval f (eval x : a)

(* Also allow annotations on multiary constructors *)
type ('a, 'b) pair = Pair of 'a * 'b

let f = function Pair ((x, y) : int * _) -> x + y