Introduction to Computational Linguistics
Introduction to Computational Linguistics
Introduction to Computational Linguistics
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3. Welcome To The Typed Universe 5<br />
isn’t there (the most frequent mistake).<br />
3 Welcome To The Typed Universe<br />
In OCaML, every expression is typed. There are certain basic types, but types can<br />
also be created. The type is named by a string. The following are inbuilt types<br />
(the list is not complete, you find a description in the user manual):<br />
(9)<br />
character<br />
string<br />
integer<br />
boolean<br />
float<br />
char<br />
string<br />
int<br />
bool<br />
float<br />
There are conventions <strong>to</strong> communicate a <strong>to</strong>ken of a given type. Characters must be<br />
enclosed in single quotes. ’a’, for example refers <strong>to</strong> the character a. Strings must<br />
be enclosed in double quotes: "mail" denotes the string mail. The distinction<br />
matters: "a" is a string, containing the single letter a. Although identical in<br />
appearance <strong>to</strong> the character a, they must be kept distinct. The next type, integer<br />
is typed in as such, for example 10763. Notice that "10763" is a string, not<br />
a number! Booleans have two values, typed in as follows: true and false.<br />
Finally, float is the type of floating point numbers. They are distinct from integers,<br />
although they may have identical values. For example, 1.0 is a number of type<br />
float, 1 is a number of type int. Type in 1.0 = 1;; and OCaML will respond<br />
with an error message:<br />
(10)<br />
# 1.0 = 1;;<br />
This expression has type int but is here used with type<br />
float<br />
And it will underline the offending item. It parses expressions from left <strong>to</strong> right<br />
and s<strong>to</strong>ps at the first point where things do not match. First it sees a number of<br />
type float and expects that <strong>to</strong> the right of the equation sign there also is a number<br />
of type float. When it reads the integer it complains. For things can only be equal<br />
via = if they have identical type.<br />
The typing is very strict. Whenever something is declared <strong>to</strong> be of certain type,<br />
it can only be used with operations that apply <strong>to</strong> things of that type. Moreover,