A type error occurs when an input argument is of the wrong type. In general,
a type is taken to be a class of terms for which there exists a unary type
test predicate. Some types are built-in, such as
integer/1. Some are defined in
library(types), such as
The type of a term is the sort of thing you can tell just
by looking at it, without checking to see how big it is. So "integer"
is a type, but "non-negative integer" is not, and "atom" is a type,
but "atom with 5 letters in its name" and "atom starting with
The point of a type error is that you have obviously passed the wrong sort of argument to a command; perhaps you have switched two arguments, or perhaps you have called the wrong predicate, but it isn't a subtle matter of being off by one.
Most built-in predicates check all their input arguments for type errors.
The exception code associated with a type error is
type_error(Goal, ArgNo, TypeName, Culprit)
Some TypeNames recognized by the system include:
0-- No type name specified
For example, suppose we had a predicate
date_plus(NumberOfDays, Date0, Date)
true when Date0 and Date were
) records and NumberOfDays was
the number of days between those two dates. You might see an error
term such as
type_error(/* Goal */ date_plus(27, date(18,mar,11), _235), /* Argno */ 2, /* TypeName */ integer, /* Culprit */ mar