Data Types Flashcards
Data types may be either:
Basic data types;
List data types;
Tuple data types;
Algebraic data types.
What is a basic data type?
A small 30 bit integer i.e. 42 :: Int
A character i.e. ‘A’ :: Char
What is a List data type?
Empty [] :: [Int]
An element prefixed to a list with :
42 : [] :: [Int]
Elements in a list must have the same type.
(a list may be written more compactly with commas)
(a list of characters can be written as a String).
What is a Tuple data type?
A tuple data type is a number of elements in parentheses separated by commas
(1, ‘abcde’, 4) :: (Int, String, Int)
Elements may have different types but there are always a fixed number.
What are algebraic types?
An algebraic type is an arbitrary combination of sums of products i.e. data Tree = Tip | Node Tree Int Tree
A polymorphic algebraic type has type variables:
data Tree a
= Tip
| Node (Tree a) a (Tree a)