File: dyn.ml

package info (click to toggle)
ocaml-re 1.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 848 kB
  • sloc: ml: 8,054; makefile: 18; sh: 11
file content (26 lines) | stat: -rw-r--r-- 543 bytes parent folder | download
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
type t =
  | Int of int
  | Tuple of t list
  | Enum of string
  | String of string
  | List of t list
  | Variant of string * t list
  | Record of (string * t) list

let variant x y = Variant (x, y)
let list x = List x
let int x = Int x
let pair x y = Tuple [ x; y ]
let record fields = Record fields
let enum x = Enum x
let string s = String s

let result ok err = function
  | Ok s -> variant "Ok" [ ok s ]
  | Error e -> variant "Error" [ err e ]
;;

let option f = function
  | None -> enum "None"
  | Some s -> variant "Some" [ f s ]
;;