annotate src/elab_err.sml @ 1680:5b2c7b9f6017

Fix fetching of keycodes for key events
author Adam Chlipala <adam@chlipala.net>
date Sun, 15 Jan 2012 14:45:06 -0500
parents 6c00d8af6239
children d6c45026240d
rev   line source
adam@1303 1 (* Copyright (c) 2008-2010, Adam Chlipala
adamc@329 2 * All rights reserved.
adamc@329 3 *
adamc@329 4 * Redistribution and use in source and binary forms, with or without
adamc@329 5 * modification, are permitted provided that the following conditions are met:
adamc@329 6 *
adamc@329 7 * - Redistributions of source code must retain the above copyright notice,
adamc@329 8 * this list of conditions and the following disclaimer.
adamc@329 9 * - Redistributions in binary form must reproduce the above copyright notice,
adamc@329 10 * this list of conditions and the following disclaimer in the documentation
adamc@329 11 * and/or other materials provided with the distribution.
adamc@329 12 * - The names of contributors may not be used to endorse or promote products
adamc@329 13 * derived from this software without specific prior written permission.
adamc@329 14 *
adamc@329 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
adamc@329 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
adamc@329 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
adamc@329 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
adamc@329 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
adamc@329 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
adamc@329 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
adamc@329 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
adamc@329 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
adamc@329 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
adamc@329 25 * POSSIBILITY OF SUCH DAMAGE.
adamc@329 26 *)
adamc@329 27
adamc@329 28 structure ElabErr :> ELAB_ERR = struct
adamc@329 29
adamc@329 30 structure L = Source
adamc@329 31 open Elab
adamc@329 32
adamc@329 33 structure E = ElabEnv
adamc@329 34 structure U = ElabUtil
adamc@329 35
adamc@329 36 open Print
adamc@329 37 structure P = ElabPrint
adamc@329 38
adamc@623 39 val simplCon = U.Con.mapB {kind = fn _ => fn k => k,
adamc@329 40 con = fn env => fn c =>
adamc@329 41 let
adamc@329 42 val c = (c, ErrorMsg.dummySpan)
adamc@628 43 val c' = ElabOps.hnormCon env c
adamc@329 44 in
adamc@329 45 (*prefaces "simpl" [("c", P.p_con env c),
adamc@329 46 ("c'", P.p_con env c')];*)
adamc@329 47 #1 c'
adamc@329 48 end,
adamc@623 49 bind = fn (env, U.Con.RelC (x, k)) => E.pushCRel env x k
adamc@792 50 | (env, U.Con.NamedC (x, n, k, co)) => E.pushCNamedAs env x n k co
adamc@623 51 | (env, _) => env}
adamc@329 52
adamc@329 53 val p_kind = P.p_kind
adamc@623 54
adamc@623 55 datatype kind_error =
adamc@623 56 UnboundKind of ErrorMsg.span * string
adamc@623 57
adamc@623 58 fun kindError env err =
adamc@623 59 case err of
adamc@623 60 UnboundKind (loc, s) =>
adamc@623 61 ErrorMsg.errorAt loc ("Unbound kind variable " ^ s)
adamc@329 62
adamc@329 63 datatype kunify_error =
adamc@329 64 KOccursCheckFailed of kind * kind
adamc@329 65 | KIncompatible of kind * kind
adam@1639 66 | KScope of kind * kind
adamc@329 67
adamc@623 68 fun kunifyError env err =
adamc@329 69 case err of
adamc@329 70 KOccursCheckFailed (k1, k2) =>
adamc@329 71 eprefaces "Kind occurs check failed"
adamc@623 72 [("Kind 1", p_kind env k1),
adamc@623 73 ("Kind 2", p_kind env k2)]
adamc@329 74 | KIncompatible (k1, k2) =>
adamc@329 75 eprefaces "Incompatible kinds"
adamc@623 76 [("Kind 1", p_kind env k1),
adamc@623 77 ("Kind 2", p_kind env k2)]
adam@1639 78 | KScope (k1, k2) =>
adam@1639 79 eprefaces "Scoping prevents kind unification"
adam@1639 80 [("Kind 1", p_kind env k1),
adam@1639 81 ("Kind 2", p_kind env k2)]
adamc@329 82
adamc@329 83 fun p_con env c = P.p_con env (simplCon env c)
adamc@329 84
adamc@329 85 datatype con_error =
adamc@329 86 UnboundCon of ErrorMsg.span * string
adamc@329 87 | UnboundDatatype of ErrorMsg.span * string
adamc@329 88 | UnboundStrInCon of ErrorMsg.span * string
adamc@329 89 | WrongKind of con * kind * kind * kunify_error
adamc@329 90 | DuplicateField of ErrorMsg.span * string
adamc@329 91 | ProjBounds of con * int
adamc@329 92 | ProjMismatch of con * kind
adamc@329 93
adamc@329 94 fun conError env err =
adamc@329 95 case err of
adamc@329 96 UnboundCon (loc, s) =>
adamc@329 97 ErrorMsg.errorAt loc ("Unbound constructor variable " ^ s)
adamc@329 98 | UnboundDatatype (loc, s) =>
adamc@329 99 ErrorMsg.errorAt loc ("Unbound datatype " ^ s)
adamc@329 100 | UnboundStrInCon (loc, s) =>
adamc@329 101 ErrorMsg.errorAt loc ("Unbound structure " ^ s)
adamc@329 102 | WrongKind (c, k1, k2, kerr) =>
adamc@329 103 (ErrorMsg.errorAt (#2 c) "Wrong kind";
adamc@329 104 eprefaces' [("Constructor", p_con env c),
adamc@623 105 ("Have kind", p_kind env k1),
adamc@623 106 ("Need kind", p_kind env k2)];
adamc@623 107 kunifyError env kerr)
adamc@329 108 | DuplicateField (loc, s) =>
adamc@329 109 ErrorMsg.errorAt loc ("Duplicate record field " ^ s)
adamc@329 110 | ProjBounds (c, n) =>
adamc@329 111 (ErrorMsg.errorAt (#2 c) "Out of bounds constructor projection";
adamc@329 112 eprefaces' [("Constructor", p_con env c),
adamc@329 113 ("Index", Print.PD.string (Int.toString n))])
adamc@329 114 | ProjMismatch (c, k) =>
adamc@329 115 (ErrorMsg.errorAt (#2 c) "Projection from non-tuple constructor";
adamc@329 116 eprefaces' [("Constructor", p_con env c),
adamc@623 117 ("Kind", p_kind env k)])
adamc@329 118
adamc@329 119 datatype cunify_error =
adamc@329 120 CKind of kind * kind * kunify_error
adamc@329 121 | COccursCheckFailed of con * con
adamc@329 122 | CIncompatible of con * con
adamc@329 123 | CExplicitness of con * con
adamc@413 124 | CKindof of kind * con * string
adam@1359 125 | CRecordFailure of con * con * (con * con * con * cunify_error option) option
adam@1303 126 | TooLifty of ErrorMsg.span * ErrorMsg.span
adam@1303 127 | TooUnify of con * con
adam@1306 128 | TooDeep
adam@1639 129 | CScope of con * con
adamc@329 130
adamc@329 131 fun cunifyError env err =
adamc@329 132 case err of
adamc@329 133 CKind (k1, k2, kerr) =>
adamc@329 134 (eprefaces "Kind unification failure"
adam@1582 135 [("Have", p_kind env k1),
adam@1582 136 ("Need", p_kind env k2)];
adamc@623 137 kunifyError env kerr)
adamc@329 138 | COccursCheckFailed (c1, c2) =>
adamc@329 139 eprefaces "Constructor occurs check failed"
adam@1582 140 [("Have", p_con env c1),
adam@1582 141 ("Need", p_con env c2)]
adamc@329 142 | CIncompatible (c1, c2) =>
adamc@329 143 eprefaces "Incompatible constructors"
adam@1582 144 [("Have", p_con env c1),
adam@1582 145 ("Need", p_con env c2)]
adamc@329 146 | CExplicitness (c1, c2) =>
adamc@329 147 eprefaces "Differing constructor function explicitness"
adam@1582 148 [("Have", p_con env c1),
adam@1582 149 ("Need", p_con env c2)]
adamc@413 150 | CKindof (k, c, expected) =>
adamc@413 151 eprefaces ("Unexpected kind for kindof calculation (expecting " ^ expected ^ ")")
adamc@623 152 [("Kind", p_kind env k),
adamc@329 153 ("Con", p_con env c)]
adamc@1071 154 | CRecordFailure (c1, c2, fo) =>
adam@1359 155 (eprefaces "Can't unify record constructors"
adam@1582 156 (("Have", p_con env c1)
adam@1582 157 :: ("Need", p_con env c2)
adam@1359 158 :: (case fo of
adam@1359 159 NONE => []
adam@1359 160 | SOME (nm, t1, t2, _) =>
adam@1359 161 [("Field", p_con env nm),
adam@1359 162 ("Value 1", p_con env t1),
adam@1359 163 ("Value 2", p_con env t2)]));
adam@1359 164 case fo of
adam@1359 165 SOME (_, _, _, SOME err') => cunifyError env err'
adam@1359 166 | _ => ())
adam@1303 167 | TooLifty (loc1, loc2) =>
adam@1303 168 (ErrorMsg.errorAt loc1 "Can't unify two unification variables that both have suspended liftings";
adam@1303 169 eprefaces' [("Other location", Print.PD.string (ErrorMsg.spanToString loc2))])
adam@1303 170 | TooUnify (c1, c2) =>
adam@1303 171 (ErrorMsg.errorAt (#2 c1) "Substitution in constructor is blocked by a too-deep unification variable";
adam@1303 172 eprefaces' [("Replacement", p_con env c1),
adam@1303 173 ("Body", p_con env c2)])
adam@1306 174 | TooDeep => ErrorMsg.error "Can't reverse-engineer unification variable lifting"
adam@1639 175 | CScope (c1, c2) =>
adam@1639 176 eprefaces "Scoping prevents constructor unification"
adam@1639 177 [("Have", p_con env c1),
adam@1639 178 ("Need", p_con env c2)]
adamc@329 179
adamc@329 180 datatype exp_error =
adamc@329 181 UnboundExp of ErrorMsg.span * string
adamc@329 182 | UnboundStrInExp of ErrorMsg.span * string
adamc@329 183 | Unify of exp * con * con * cunify_error
adamc@339 184 | Unif of string * ErrorMsg.span * con
adamc@329 185 | WrongForm of string * exp * con
adamc@329 186 | IncompatibleCons of con * con
adamc@329 187 | DuplicatePatternVariable of ErrorMsg.span * string
adamc@329 188 | PatUnify of pat * con * con * cunify_error
adamc@329 189 | UnboundConstructor of ErrorMsg.span * string list * string
adamc@329 190 | PatHasArg of ErrorMsg.span
adamc@329 191 | PatHasNoArg of ErrorMsg.span
adamc@819 192 | Inexhaustive of ErrorMsg.span * pat
adamc@329 193 | DuplicatePatField of ErrorMsg.span * string
adamc@329 194 | Unresolvable of ErrorMsg.span * con
adamc@329 195 | OutOfContext of ErrorMsg.span * (exp * con) option
adamc@329 196 | IllegalRec of string * exp
adamc@329 197
adamc@329 198 val p_exp = P.p_exp
adamc@329 199 val p_pat = P.p_pat
adamc@329 200
adamc@329 201 fun expError env err =
adamc@329 202 case err of
adamc@329 203 UnboundExp (loc, s) =>
adamc@329 204 ErrorMsg.errorAt loc ("Unbound expression variable " ^ s)
adamc@329 205 | UnboundStrInExp (loc, s) =>
adamc@329 206 ErrorMsg.errorAt loc ("Unbound structure " ^ s)
adamc@329 207 | Unify (e, c1, c2, uerr) =>
adamc@329 208 (ErrorMsg.errorAt (#2 e) "Unification failure";
adamc@329 209 eprefaces' [("Expression", p_exp env e),
adamc@329 210 ("Have con", p_con env c1),
adamc@329 211 ("Need con", p_con env c2)];
adamc@329 212 cunifyError env uerr)
adamc@339 213 | Unif (action, loc, c) =>
adamc@339 214 (ErrorMsg.errorAt loc ("Unification variable blocks " ^ action);
adamc@329 215 eprefaces' [("Con", p_con env c)])
adamc@329 216 | WrongForm (variety, e, t) =>
adamc@329 217 (ErrorMsg.errorAt (#2 e) ("Expression is not a " ^ variety);
adamc@329 218 eprefaces' [("Expression", p_exp env e),
adamc@329 219 ("Type", p_con env t)])
adamc@329 220 | IncompatibleCons (c1, c2) =>
adamc@329 221 (ErrorMsg.errorAt (#2 c1) "Incompatible constructors";
adam@1582 222 eprefaces' [("Have", p_con env c1),
adam@1582 223 ("Need", p_con env c2)])
adamc@329 224 | DuplicatePatternVariable (loc, s) =>
adamc@329 225 ErrorMsg.errorAt loc ("Duplicate pattern variable " ^ s)
adamc@329 226 | PatUnify (p, c1, c2, uerr) =>
adamc@329 227 (ErrorMsg.errorAt (#2 p) "Unification failure for pattern";
adamc@329 228 eprefaces' [("Pattern", p_pat env p),
adamc@329 229 ("Have con", p_con env c1),
adamc@329 230 ("Need con", p_con env c2)];
adamc@329 231 cunifyError env uerr)
adamc@329 232 | UnboundConstructor (loc, ms, s) =>
adamc@329 233 ErrorMsg.errorAt loc ("Unbound constructor " ^ String.concatWith "." (ms @ [s]) ^ " in pattern")
adamc@329 234 | PatHasArg loc =>
adamc@329 235 ErrorMsg.errorAt loc "Constructor expects no argument but is used with argument"
adamc@329 236 | PatHasNoArg loc =>
adamc@329 237 ErrorMsg.errorAt loc "Constructor expects argument but is used with no argument"
adamc@819 238 | Inexhaustive (loc, p) =>
adamc@819 239 (ErrorMsg.errorAt loc "Inexhaustive 'case'";
adamc@819 240 eprefaces' [("Missed case", p_pat env p)])
adamc@329 241 | DuplicatePatField (loc, s) =>
adamc@329 242 ErrorMsg.errorAt loc ("Duplicate record field " ^ s ^ " in pattern")
adamc@329 243 | OutOfContext (loc, co) =>
adamc@329 244 (ErrorMsg.errorAt loc "Type class wildcard occurs out of context";
adamc@329 245 Option.app (fn (e, c) => eprefaces' [("Function", p_exp env e),
adamc@329 246 ("Type", p_con env c)]) co)
adamc@329 247 | Unresolvable (loc, c) =>
adamc@329 248 (ErrorMsg.errorAt loc "Can't resolve type class instance";
adamc@850 249 eprefaces' [("Class constraint", p_con env c)(*,
adamc@711 250 ("Class database", p_list (fn (c, rules) =>
adamc@711 251 box [P.p_con env c,
adamc@711 252 PD.string ":",
adamc@711 253 space,
adamc@711 254 p_list (fn (c, e) =>
adamc@711 255 box [p_exp env e,
adamc@711 256 PD.string ":",
adamc@711 257 space,
adamc@711 258 P.p_con env c]) rules])
adamc@850 259 (E.listClasses env))*)])
adamc@329 260 | IllegalRec (x, e) =>
adamc@329 261 (ErrorMsg.errorAt (#2 e) "Illegal 'val rec' righthand side (must be a function abstraction)";
adamc@329 262 eprefaces' [("Variable", PD.string x),
adamc@329 263 ("Expression", p_exp env e)])
adamc@329 264
adamc@329 265
adamc@329 266 datatype decl_error =
adamc@329 267 KunifsRemain of decl list
adamc@329 268 | CunifsRemain of decl list
adamc@329 269 | Nonpositive of decl
adamc@329 270
adamc@329 271 fun lspan [] = ErrorMsg.dummySpan
adamc@329 272 | lspan ((_, loc) :: _) = loc
adamc@329 273
adam@1584 274 val baseLen = 2000
adam@1584 275
adam@1584 276 fun p_decl env d =
adam@1584 277 let
adam@1584 278 val fname = OS.FileSys.tmpName ()
adam@1584 279 val out' = TextIO.openOut fname
adam@1584 280 val out = Print.openOut {dst = out', wid = 80}
adam@1584 281
adam@1584 282 fun readFromFile () =
adam@1584 283 let
adam@1584 284 val inf = TextIO.openIn fname
adam@1584 285
adam@1584 286 fun loop acc =
adam@1584 287 case TextIO.inputLine inf of
adam@1584 288 NONE => String.concat (rev acc)
adam@1584 289 | SOME line => loop (line :: acc)
adam@1584 290 in
adam@1584 291 loop []
adam@1584 292 before TextIO.closeIn inf
adam@1584 293 end
adam@1584 294 in
adam@1584 295 Print.fprint out (P.p_decl env d);
adam@1584 296 TextIO.closeOut out';
adam@1584 297 let
adam@1584 298 val content = readFromFile ()
adam@1584 299 in
adam@1584 300 OS.FileSys.remove fname;
adam@1584 301 Print.PD.string (if size content <= baseLen then
adam@1584 302 content
adam@1584 303 else
adam@1584 304 let
adam@1584 305 val (befor, after) = Substring.position "<UNIF:" (Substring.full content)
adam@1584 306 in
adam@1584 307 if Substring.isEmpty after then
adam@1584 308 raise Fail "No unification variables in rendering"
adam@1584 309 else
adam@1584 310 Substring.concat [Substring.full "\n.....\n",
adam@1584 311 if Substring.size befor <= baseLen then
adam@1584 312 befor
adam@1584 313 else
adam@1584 314 Substring.slice (befor, Substring.size befor - baseLen, SOME baseLen),
adam@1584 315 if Substring.size after <= baseLen then
adam@1584 316 after
adam@1584 317 else
adam@1584 318 Substring.slice (after, 0, SOME baseLen),
adam@1584 319 Substring.full "\n.....\n"]
adam@1584 320 end)
adam@1584 321 end
adam@1584 322 end
adamc@329 323
adamc@329 324 fun declError env err =
adamc@329 325 case err of
adamc@329 326 KunifsRemain ds =>
adam@1521 327 (ErrorMsg.errorAt (lspan ds) "Some kind unification variables are undetermined in declaration\n(look for them as \"<UNIF:...>\")";
adamc@329 328 eprefaces' [("Decl", p_list_sep PD.newline (p_decl env) ds)])
adamc@329 329 | CunifsRemain ds =>
adam@1521 330 (ErrorMsg.errorAt (lspan ds) "Some constructor unification variables are undetermined in declaration\n(look for them as \"<UNIF:...>\")";
adamc@329 331 eprefaces' [("Decl", p_list_sep PD.newline (p_decl env) ds)])
adamc@329 332 | Nonpositive d =>
adamc@329 333 (ErrorMsg.errorAt (#2 d) "Non-strictly-positive datatype declaration (could allow non-termination)";
adamc@329 334 eprefaces' [("Decl", p_decl env d)])
adamc@329 335
adamc@329 336 datatype sgn_error =
adamc@329 337 UnboundSgn of ErrorMsg.span * string
adamc@1000 338 | UnmatchedSgi of ErrorMsg.span * sgn_item
adamc@1000 339 | SgiWrongKind of ErrorMsg.span * sgn_item * kind * sgn_item * kind * kunify_error
adamc@1000 340 | SgiWrongCon of ErrorMsg.span * sgn_item * con * sgn_item * con * cunify_error
adamc@1000 341 | SgiMismatchedDatatypes of ErrorMsg.span * sgn_item * sgn_item
adamc@1000 342 * (con * con * cunify_error) option
adamc@1000 343 | SgnWrongForm of ErrorMsg.span * sgn * sgn
adamc@329 344 | UnWhereable of sgn * string
adamc@329 345 | WhereWrongKind of kind * kind * kunify_error
adamc@329 346 | NotIncludable of sgn
adamc@329 347 | DuplicateCon of ErrorMsg.span * string
adamc@329 348 | DuplicateVal of ErrorMsg.span * string
adamc@329 349 | DuplicateSgn of ErrorMsg.span * string
adamc@329 350 | DuplicateStr of ErrorMsg.span * string
adamc@329 351 | NotConstraintsable of sgn
adamc@329 352
adamc@329 353 val p_sgn_item = P.p_sgn_item
adamc@329 354 val p_sgn = P.p_sgn
adamc@329 355
adamc@329 356 fun sgnError env err =
adamc@329 357 case err of
adamc@329 358 UnboundSgn (loc, s) =>
adamc@329 359 ErrorMsg.errorAt loc ("Unbound signature variable " ^ s)
adamc@1000 360 | UnmatchedSgi (loc, sgi) =>
adamc@329 361 (ErrorMsg.errorAt loc "Unmatched signature item";
adamc@329 362 eprefaces' [("Item", p_sgn_item env sgi)])
adamc@1000 363 | SgiWrongKind (loc, sgi1, k1, sgi2, k2, kerr) =>
adamc@1000 364 (ErrorMsg.errorAt loc "Kind unification failure in signature matching:";
adamc@329 365 eprefaces' [("Have", p_sgn_item env sgi1),
adamc@329 366 ("Need", p_sgn_item env sgi2),
adamc@623 367 ("Kind 1", p_kind env k1),
adamc@623 368 ("Kind 2", p_kind env k2)];
adamc@623 369 kunifyError env kerr)
adamc@1000 370 | SgiWrongCon (loc, sgi1, c1, sgi2, c2, cerr) =>
adamc@1000 371 (ErrorMsg.errorAt loc "Constructor unification failure in signature matching:";
adamc@329 372 eprefaces' [("Have", p_sgn_item env sgi1),
adamc@329 373 ("Need", p_sgn_item env sgi2),
adamc@329 374 ("Con 1", p_con env c1),
adamc@329 375 ("Con 2", p_con env c2)];
adamc@329 376 cunifyError env cerr)
adamc@1000 377 | SgiMismatchedDatatypes (loc, sgi1, sgi2, cerro) =>
adamc@1000 378 (ErrorMsg.errorAt loc "Mismatched 'datatype' specifications:";
adamc@329 379 eprefaces' [("Have", p_sgn_item env sgi1),
adamc@329 380 ("Need", p_sgn_item env sgi2)];
adamc@329 381 Option.app (fn (c1, c2, ue) =>
adamc@329 382 (eprefaces "Unification error"
adamc@329 383 [("Con 1", p_con env c1),
adamc@329 384 ("Con 2", p_con env c2)];
adamc@329 385 cunifyError env ue)) cerro)
adamc@1000 386 | SgnWrongForm (loc, sgn1, sgn2) =>
adamc@1000 387 (ErrorMsg.errorAt loc "Incompatible signatures:";
adamc@329 388 eprefaces' [("Sig 1", p_sgn env sgn1),
adamc@329 389 ("Sig 2", p_sgn env sgn2)])
adamc@329 390 | UnWhereable (sgn, x) =>
adamc@329 391 (ErrorMsg.errorAt (#2 sgn) "Unavailable field for 'where'";
adamc@329 392 eprefaces' [("Signature", p_sgn env sgn),
adamc@329 393 ("Field", PD.string x)])
adamc@329 394 | WhereWrongKind (k1, k2, kerr) =>
adamc@329 395 (ErrorMsg.errorAt (#2 k1) "Wrong kind for 'where'";
adamc@623 396 eprefaces' [("Have", p_kind env k1),
adamc@623 397 ("Need", p_kind env k2)];
adamc@623 398 kunifyError env kerr)
adamc@329 399 | NotIncludable sgn =>
adamc@329 400 (ErrorMsg.errorAt (#2 sgn) "Invalid signature to 'include'";
adamc@329 401 eprefaces' [("Signature", p_sgn env sgn)])
adamc@329 402 | DuplicateCon (loc, s) =>
adamc@329 403 ErrorMsg.errorAt loc ("Duplicate constructor " ^ s ^ " in signature")
adamc@329 404 | DuplicateVal (loc, s) =>
adamc@329 405 ErrorMsg.errorAt loc ("Duplicate value " ^ s ^ " in signature")
adamc@329 406 | DuplicateSgn (loc, s) =>
adamc@329 407 ErrorMsg.errorAt loc ("Duplicate signature " ^ s ^ " in signature")
adamc@329 408 | DuplicateStr (loc, s) =>
adamc@329 409 ErrorMsg.errorAt loc ("Duplicate structure " ^ s ^ " in signature")
adamc@329 410 | NotConstraintsable sgn =>
adamc@329 411 (ErrorMsg.errorAt (#2 sgn) "Invalid signature for 'open constraints'";
adamc@329 412 eprefaces' [("Signature", p_sgn env sgn)])
adamc@329 413
adamc@329 414 datatype str_error =
adamc@329 415 UnboundStr of ErrorMsg.span * string
adamc@329 416 | NotFunctor of sgn
adamc@329 417 | FunctorRebind of ErrorMsg.span
adamc@329 418 | UnOpenable of sgn
adamc@706 419 | NotType of ErrorMsg.span * kind * (kind * kind * kunify_error)
adamc@329 420 | DuplicateConstructor of string * ErrorMsg.span
adamc@329 421 | NotDatatype of ErrorMsg.span
adamc@329 422
adamc@329 423 fun strError env err =
adamc@329 424 case err of
adamc@329 425 UnboundStr (loc, s) =>
adamc@329 426 ErrorMsg.errorAt loc ("Unbound structure variable " ^ s)
adamc@329 427 | NotFunctor sgn =>
adamc@329 428 (ErrorMsg.errorAt (#2 sgn) "Application of non-functor";
adamc@329 429 eprefaces' [("Signature", p_sgn env sgn)])
adamc@329 430 | FunctorRebind loc =>
adamc@329 431 ErrorMsg.errorAt loc "Attempt to rebind functor"
adamc@329 432 | UnOpenable sgn =>
adamc@329 433 (ErrorMsg.errorAt (#2 sgn) "Un-openable structure";
adamc@329 434 eprefaces' [("Signature", p_sgn env sgn)])
adamc@706 435 | NotType (loc, k, (k1, k2, ue)) =>
adamc@706 436 (ErrorMsg.errorAt loc "'val' type kind is not 'Type'";
adamc@623 437 eprefaces' [("Kind", p_kind env k),
adamc@623 438 ("Subkind 1", p_kind env k1),
adamc@623 439 ("Subkind 2", p_kind env k2)];
adamc@623 440 kunifyError env ue)
adamc@329 441 | DuplicateConstructor (x, loc) =>
adamc@329 442 ErrorMsg.errorAt loc ("Duplicate datatype constructor " ^ x)
adamc@329 443 | NotDatatype loc =>
adamc@329 444 ErrorMsg.errorAt loc "Trying to import non-datatype as a datatype"
adamc@329 445
adamc@329 446 end