In Haskell, there are several basic data types that are used to build more complex data structures. Here are some of the most common ones:
1. **Int:** This type represents fixed-precision integers. The exact range of numbers it can represent depends on the architecture of the machine, but it usually corresponds to the machine’s native ‘int‘ size, typically 32 or 64 bits.
2. **Integer:** This type represents integers with arbitrary precision. Unlike ‘Int‘, which has limited range, ‘Integer‘ can represent any whole number, no matter how large, at the cost of lower performance.
3. **Float:** This type represents single-precision floating-point numbers, that is, real numbers approximately with 7 significant digits of precision.
4. **Double:** This type represents double-precision floating-point numbers, which are real numbers with approximately 15 significant digits of precision.
5. **Bool:** This type represents Boolean values, which can be either ‘True‘ or ‘False‘.
6. **Char:** This type represents Unicode characters.
7. **Tuples:** Tuples are a collection of values indexed by their position. The number of elements that a tuple can have is called its arity (a 2-element tuple is a pair, a 3-element tuple is a triple, and so on). Different arity tuples are distinct types.
For example, a 2-element tuple (pair) has the type ‘(a, b)‘, where ‘a‘ and ‘b‘ can be any types of values, such as ‘Int‘, ‘Float‘, or ‘Bool‘. A 3-element tuple (triple) has the type ‘(a, b, c)‘.
Here’s a simple example of defining some basic data types in Haskell:
intExample :: Int
intExample = 42
integerExample :: Integer
integerExample = 123456789012345
floatExample :: Float
floatExample = 3.14
doubleExample :: Double
doubleExample = 3.14159265358979
boolExample :: Bool
boolExample = True
charExample :: Char
charExample = 'a'
pairExample :: (Int, Bool)
pairExample = (42, True)
tripleExample :: (Int, Bool, Char)
tripleExample = (42, True, 'a')
Note that the ‘::‘ symbol in the above example is used to denote the type annotation for each value.