F# Lists

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • [] // an empty list.

    head::tail // a construction cell holding an element, head, and a list, tail. :: is called the Cons operator.

    let list1 = [ 1; 2; 3 ] // Note the usage of a semicolon.

    let list2 = 0 :: list1 // result is [ 0; 1; 2; 3 ]

    let list3 = list1 @ list2 // result is [ 1; 2; 3; 0; 1; 2; 3 ]. @ is the append operator.

    let list4 = [ 1..3 ] // result is [ 1; 2; 3 ]

    let list5 = [ 1..2..10 ] // result is [ 1; 3; 5; 7; 9 ]

    let list6 = [ for i in 1..10 do if i % 2 = 1 then yield i ] // result is [ 1; 3; 5; 7; 9 ]



Got any F# Question?