You are on page 1of 4

C++ Data types

Name Description Size* Range*


signed: -128 to 127
char Character or small integer. 1byte
unsigned: 0 to 255
short int signed: -32768 to 32767
Short Integer. 2bytes
(short) unsigned: 0 to 65535
signed: -2147483648 to
2147483647
int Integer. 4bytes
unsigned: 0 to
4294967295
signed: -2147483648 to
long int 2147483647
Long integer. 4bytes
(long) unsigned: 0 to
4294967295
Boolean value. It can take one of two
bool 1byte true or false
values: true or false.
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
Double precision floating point +/- 1.7e +/- 308 (~15
double 8bytes
number. digits)
long Long double precision floating point +/- 1.7e +/- 308 (~15
8bytes
double number. digits)
2 or 4
wchar_t Wide character. 1 wide character
bytes

Fortran Data types

Data Types

FORTRAN supports six data types:

CHARACTER
character
COMPLEX
single precision complex number
DOUBLE PRECISION
double precision floating point number
INTEGER
integer
LOGICAL
boolean (true or false)
REAL
single precision floating point number
Scheme Data types
Booleans

Booleans are either


#t

(true) or
#f

(false), booleans are self-evaluating.


Numbers

Numbers are self-evaluating, and are entered as expected. Scheme also supports
complex numbers as for instance
0+4i

. Just typing
4i

is interpreted as a symbol in Scheme, beware.


Characters

Characters are self-evaluating and entered as such


#\a

.
Symbols

Symbols are sequences of characters, different from strings because they are not
self-evaluating, and they can't contain white-space either. They are just input by
typing them really, for instance
(add one two)

is a list in Scheme that contains three symbols.

Perl Data types


Scalars

Scalar variables are used to store single values - for example, a number or a string.
They are preceded by the dollar sign ($).

Arrays (lists)

Arrays, often called lists, can store a list of many scalar values at once. They are
preceded by the at sign (@)
Associative arrays (hashes)

The final data type we're going to cover here is the associative array, often called
ahash. Associative arrays are similar to normal arrays, with one important difference.
Instead of using numbers to index each element in an array, you can use more
meaningful strings.

Hash variables are preceded by the percent sign (%).

Prolog Data types

ABSTRACT

This module implements a class to be used from interfaces to Prolog systems (SWI-
Prolog, XSB, etc.) to transform complex Perl data types to Prolog types.

METHODS

Language::Prolog::Types::Converter->new()>

returns a new converter object.

EXPORT

None by default. This module has an OO interface.

Hakell Data types

Pattern Matching

You should note that in the constructor declarations I didn't give the arguments
names, but rather simply specified their types. The reasoning behind this is clear as
we see pattern matching in action.

The Case Expression

It's important to note that this kind of pattern matching is also how Haskell's case
expression works.

Robustness

Of course, this isn't very robust. There's no definition of lastName for Name1 or
NoName, and firstName isn't defined for NoName. Obviously, this is because those
forms of Name don't have the data we're trying to extra.

Polymorphism

Let's take a simple example. We want a function which will converta Name into a
suitable String for output. In Haskell we normally use the show function to do just
this. Getting show (and functions which rely on it) to accept a Name is a matter of
polymorphism.

Deriving

Similarly, we can check for equality between names by making Name an instance of
the Eq class. This class is interesting because it declares two functions: the ==
and /= operators, but it provides a default definition for the /= operator.

Polymorphism with a Custom Class

Of course, nothing limits us to classes included in the standard library. Let's define a
new data type which incorporates a Name. We then have two new functions to get
the first and last names.

You might also like