Introduction: List is a collection of
related values. It is same as linked list data structure used in other
languages. List allows us to link data together to form a chain. List plays an
important role in functional programming. It can be an Empty list, List of fixed values or a list value concatenated to it. The below table shows the primitive
constructs for building lists.
| Expression | Description |
| [ ] | For empty List |
| [value1;...;valuen] | List element |
| Exp::Exp | concatenate element with a List. Two colons (::), pronounced as "cons" here. |
| [exp .. exp] | A range of Integers |
| [for X in List -> exp] | A generated List |
| exp @ exp | Concatenates two Lists |
Defining List:
Empty List: An empty List is represented by a square bracket(
[ ] ).
Syntax:
let listname=[]
Like,
let
emptylist= [ ]
List With Fix Elements: A simple list is defined with an element in square brackets. The list elements are
separated with semicolons.
Syntax:
let simplelist=[element1;element2;elementn]
Like,
let
simplelist= [1;2;3;4;5 ]
let simplelist=['A';'B';'C';'D';'E']
let simplelist=["AAA";"BBB";"CCC"]
Or, We can also put line breaks among list element. Semicolon are optional
here.
Like, let simplelist=[
element1
element2
elementn]
Example,
let
simplelist= [1
2
3]
We write the following code





Join the conversation! Your thoughts help the community grow.