Data Types Flashcards

1
Q

Data types may be either:

A

Basic data types;
List data types;
Tuple data types;
Algebraic data types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a basic data type?

A

A small 30 bit integer i.e. 42 :: Int

A character i.e. ‘A’ :: Char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a List data type?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Tuple data type?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are algebraic types?

A
An algebraic type is an arbitrary combination of sums of products
i.e.
data Tree
      = Tip
       | Node Tree Int Tree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A polymorphic algebraic type has type variables:

A

data Tree a
= Tip
| Node (Tree a) a (Tree a)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly