Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Both sides next revision
alvis:typesparameters [2017/01/11 22:40]
marcin removed
— (current)
Line 1: Line 1:
-====== Types and parameters ====== 
  
-Alvis uses the **Haskell's type system**. Types in Haskell are **strong**, **static** and can be automatically **inferred**. The **strong** property means that the type system guarantees that a program cannot contain errors coming from using improper data types, such as using a string as an integer. Moreover, Haskell does not automatically coerce values from one type to another.  
-The **static** property means that the compiler knows the type of every value and expression at compile time, before any code is executed. Haskell's combination of strong and static typing makes it impossible for type errors to occur at runtime. 
- 
-====== Basic data types ====== 
- 
-Selected basic Haskell types recommended to be used in Alvis are as follows: 
-  * **Char** -- Unicode characters. 
-  * **Bool** -- Values in Boolean logic (**True** and **False**). 
-  * **Int** -- Fixed-width integer values -- The exact range of values represented as **Int** depends on the system's longest native integer. 
-  * **Double** -- Float-point numbers typically 64 bits wide and uses the system's native floating-point representation. 
- 
-====== Composite data types ====== 
- 
-The most common composite data types in Haskell (and Alvis) are **lists** and **tuples**.  
- 
-  * **Lists** -- A **list** is a sequence of elements of the same type, with the elements being enclosed in square brackets and separated by commas. 
-  * **Tuples** -- A **tuple** is a sequence of elements of possibly different types, with the elements being enclosed in parentheses and separated by commas. Tuples containing different number of types of elements have disting types, as do tuple whose types appear in different orders. 
- 
-**Remark:** Haskell represents a text string as a list of **Char** values, but the name **String** can be used. 
- 
-<code> 
-[1,2,3,4]        -- type [Int] 
-['a','b','c'   -- type [Char] (String) 
-[True,False]     -- type [Bool] 
-(1,2)            -- type (Int,Int) 
-('a',True)       -- type (Char,Bool) 
-("abc",1,True)   -- type (String,Int,Bool) 
-</code> 
- 
-**Listing 1. ** Examples of Haskell composite data types 
- 
- 
-====== Agents' parameters ====== 
- 
-Parameters are defined using the Haskell syntax. Each parameter is placed in a separate line. The line starts with a parameter name, then the **::** symbol is placed followed by the parameter type. The type must be followed by the **=** symbol and the parameter initial value as shown in Listings 6 and 7. 
- 
-<code> 
-size      :: Int         = 7; 
-queue     :: [Double]    = []; 
-inputData :: (Int, Char) = (0, 'x'); 
-</code> 
- 
-**Listing 6. ** Examples of parameters definitions 
- 
-<code> 
-agent Buffer { 
-  v :: Int = 0; 
-  -- ... 
-} 
-</code> 
- 
-**Listing 2. ** Part of Buffer agent implementation with a parameter definition 
- 
- 
- 
- 
-**[[:alvis:manual|Go back]]**