package alba
Alba compiler
Install
Dune Dependency
Authors
Maintainers
Sources
0.4.4.tar.gz
sha256=4817038301d3e45bac9edf7e6f2fc8bf0a6d78e76e02ad7ea33ef69bcc17df3b
md5=25234357587126685d64f16236167937
doc/src/alba.albalib/test_inductive.ml.html
Source file test_inductive.ml
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
open Alba_core open Ast module Inductive_parser = Parser_lang.Make ( struct type t = Source_entry.inductive array end) module Expression_parser = Parser_lang.Make (Expression) let add_inductive (src: string) (c: Context.t) : (Context.t, Build_problem.t) result = let open Inductive_parser in let p = run (inductive_family ()) src in assert (has_ended p); assert (has_succeeded p); match result p with | None -> assert false | Some inds -> Builder.add_inductive inds c let build_expression (src: string) (c: Context.t): (Term.t * Term.typ, Build_problem.t) result = let open Expression_parser in let p = run (expression ()) src in assert (has_ended p); assert (has_succeeded p); match result p with | None -> assert false (* Syntax error *) | Some exp -> Build_expression.build exp c (* Test the inductive types ------------------------ - same number of parameters - same parameter names - same parameter types - inductive type must be a type (i.e. its type a kind) *) let%test _ = let src = "class I0 A :=\n\ class I1 A B :=" in match add_inductive src Context.empty with | Error (_, Build_problem.Wrong_parameter_count _) -> true | _ -> false let%test _ = let src = "class I0 A :=\n\ class I1 B :=" in match add_inductive src Context.empty with | Error (_, Build_problem.Wrong_parameter_name _) -> true | _ -> false let%test _ = let src = "class I0 (A: Any -> Any) :=\n\ class I1 A :=" in match add_inductive src Context.empty with | Error (_, Build_problem.Wrong_parameter_type _) -> true | _ -> false let%test _ = let src = "class i A: Int :=" and context = Context.( empty |> add_builtin_type "int_type" "Int" Term.any ) in match add_inductive src context with | Error (_, Build_problem.No_inductive_type) -> true | _ -> false let%test _ = let src = "class I :=\n\ class I :=" in match add_inductive src Context.empty with | Error (_, Build_problem.Duplicate_inductive) -> true | _ -> false (* Test the constructors ------------------------ - no duplicate constructor names - if there are indices, then type must be explicit - construct a object of the corresponding inductive type - positivity - positivity in family - positivity with other inductive type *) let%test _ = let src = "class I := c; c" in match add_inductive src Context.empty with | Error (_, Build_problem.Duplicate_constructor) -> true | _ -> false let%test _ = let src = "class I A: A -> Any := constr" in match add_inductive src Context.empty with | Error (_, Build_problem.Missing_inductive_type) -> true | _ -> false let%test _ = let src = "class I A := Constr: Any" in match add_inductive src Context.empty with | Error (_, Build_problem.Wrong_type_constructed _) -> true | _ -> false let%test _ = let src = "class I A := constr: I Proposition" in match add_inductive src Context.empty with | Error (_, Build_problem.Wrong_type_constructed _) -> true | _ -> false let%test _ = let src = "class I := constr: (I -> Proposition) -> I" in match add_inductive src Context.empty with | Error (_, Build_problem.Negative) -> true | _ -> false let%test _ = let src = "class I A := constr: I (I A) -> I A" in match add_inductive src Context.empty with | Error (_, Build_problem.Not_positive _) -> true | _ -> false let%test _ = let src1 = "class I1 A := co1: (A -> A) -> I1 A" and src2 = "class I := co : I1 I -> I" in match add_inductive src1 Context.empty with | Error _ -> false | Ok c -> match add_inductive src2 c with | Error (_, Build_problem.Nested_negative _) -> true | _ -> false let%test _ = let open Fmlib.Result in let src1 = "Any -> Any" and src2 = "class II := co : TC II -> II" in match ( build_expression src1 Context.empty >>= fun (typ, _) -> add_inductive src2 (Context.(add_builtin_type "TC" "TC" typ empty)) ) with | Error (_, Not_positive _) -> true | _ -> false
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>