Tutorial by Examples

let list1 = [ 1; 2 ] let list2 = [ 1 .. 100 ] // Accessing an element printfn "%A" list1.[0] // Pattern matching let rec patternMatch aList = match aList with | [] -> printfn "This is an empty list" | head::tail -> printfn "This list consists o...
By recursion let rec sumTotal list = match list with | [] -> 0 // empty list -> return 0 | head :: tail -> head + sumTotal tail The above example says: "Look at the list, is it empty? return 0. Otherwise it is a non-empty list. So it could be [1], [1; 2], [1; 2; 3] ...
A way to create a list is to place elements in two square brackets, separated by semicolons. The elements must have the same type. Example: > let integers = [1; 2; 45; -1];; val integers : int list = [1; 2; 45; -1] > let floats = [10.7; 2.0; 45.3; -1.05];; val floats : float list = [1...

Page 1 of 1