Sie sind auf Seite 1von 5

List of type errors handled by the OCaml compiler and the associated messages

Shaun Hall sh580@cam.ac.uk November 8, 2010

Errors handled from typecore.ml


Polymorphic label
type t = {x: a. a list};; let f y = match y with {x = 5::_} -> true;; Error: The record field label x is polymorphic. You cannot instantiate it in a pattern.

Constructor arity mismatch


type Car = Bike of int;; Bike;; Error: The constructor Bike expects 1 argument(s), but is applied here to 0 argument(s) Gives a type unication error in the case Bike 0 0, so inconsistent reporting.

Label mismatch
type point_3d = {x : float; y : float; z : float};; type point_2d = {x : float; y : float};; {x = 10.; y = 20.; z = 30.};; Error: The record field label z belongs to the type point_3d but is mixed here with labels of type point_2d

Pattern type clash


type foo = Bar of int type bar = Foo of int let f x = match x with Bar(y) -> "" | Foo(y) ->"";; Error: This pattern matches values of type bar but a pattern was expected which matches values of type foo

Multiply bound variable name


let d = (3, 3, 4) in match d with ( a, a, c ) -> (a, c);; Error: Variable a is bound several times in this matching

Orpat vars id
let product a b = match (a, b) with (a, 0.) | (0., b) -> 0. | (a, b) -> a *. b;; Error: Variable a must occur on both sides of this | pattern Note: Prevents matching where variable will not be used - enforces good programming practice - must use _ if value is not later used.

Expr type clash


let f x = x+1;; f "";; Error: This expression has type string but an expression was expected of type int.

Apply non function


let g x = true and f x = x in g f 3;; Error: This function is applied to too many arguments; maybe you forgot a ;. Note: The above gives the error below when application order is made explicit - inconsistent typing. let g x = true and f x = x in (g f) 3;; Error: This expression is not a function, it cannot be applied

Apply wrong label


let f ~(x:int) ~(y:int) = 0;; f 3;; Error: The function applied to this argument has type x:int -> y:int -> int This argument cannot be applied without label

Label multiply dened, Label missing labels, Abstract wrong label, Incoherent label order
type t = {x: int; y:int};; {x = 3};; Some record field labels are undefined: y

Label not mutable lid


type foo = {bar:string};; let p = {bar=""};; p.bar <- "hi";; The record field label bar is not mutable

Incomplete format
Printf.printf "%";; Error: Premature end of format string "%"

Bad conversion
Bad conversion %%%c, at char number %d

Undened method
Object-oriented feature, as is Undened inherited method, Virtual class, Unbound instance variable, Instance variable not mutable, Not subtype(tr1, tr2), Outside class, Value multiply overridden, Coercion failure, Masked instance variable, Private type, Private label 2

Too many arguments


[(fun n->n+1);(fun n m->n+m)];; Error: This function expects too many arguments, it should have type int -> int

Scoping let module


let module M = struct type t = C of int let x = C 3 end in M.x;; Error: This let module expression has type M.t In this type, the locally bound module name M escapes its scope

Not a variant type


type t = [A | B];; Error: The type a is not a polymorphic variant type

Less general
type t = {x: a. a list};; {x = [3]};; Error: This field value has type int list which is less general than a. a list

Errors handled from typetexp.ml


The errors below result from errors from unication of types.

Unbound type variable, Unbound type constructor, Unbound type constructor 2


type foo = Cons of a;; ^^ Error: Unbound type parameter a let f x:bar = x;; ^^^ Error: Unbound type constructor bar

Type arity mismatch


type car = Bike of int;; let f x:(a car) = x;; ^^^^^^ Error: The type constructor car expects 0 arg but is here applied to 1 argument(s)

Recursive type
type a a = a a;; ^^^^^^^^^^^^ Error: The type abbreviation a is cyclic

Alias type mismatch


type a t = Cons of a;; fun (x:a t as a) -> x;; ^^^^^^^^^^ Error: This alias is bound to type a t but is used as an instance of type a

Unbound row variable, Cannot quantify, Multiple constraints on type, Repeated method label, Unbound class, Unbound label, Unbound cltype
Object-oriented features.

Type mismatch
Obsolete.

Present has conjunction, Present has no type


let f x:[< a > b] = x;; The present constructor B has no type

Constructor mismatch, Not a variant, Variant tags


Errors from unication of variant types.

Invalid variable name


type t = _a list;; ^^^ Error: The type variable name _a is not allowed in programs

Unbound value
x;; ^ Error: Unbound value x

Unbound constructor
Car 3;; ^^^^^ Error: Unbound constructor Car

Unbound modtype, Ill-typed functor application


Occurs in functors that map modules to modules

Unbound module
open Blah;; ^^^^^^^^^ Error: Unbound module Blah

Das könnte Ihnen auch gefallen