Homepage / Notes / Computer Science / Programming Languages / F#
Type inference
"Hello, World!"
val it: string = "Hello, World!"
let myInt = 9
val myInt: int = 9
Commas are never user as delimiters, only semicolons
let firstList = [1; 2; 3]
val firstList: int list = [1; 2; 3]
[1..5]
val it: int list = [1; 2; 3; 4; 5]
[for i in 1..10 do i * i]
val it: int list = [1; 4; 9; 16; 25; 36; 49; 64; 81; 100]
let square x = x * x
4 square
val square: x: int -> int
val it: int = 16
let add x y = x + y
2 3 add
val add: x: int -> y: int -> int
val it: int = 5
.map (fun x -> x * x) [1; 2; 3] List
val it: int list = [1; 4; 9]
let x = "a"
match x with
"a" -> "x is a"
| "b" -> "x is b"
| "x is neither" | _ ->
val x: string = "a"
val it: string = "x is a"
.map square firstList |> List
val it: int list = [1; 4; 9]
.map square |> List.sum firstList |> List
val it: int = 14
.sum <| [1; 2; 3; 4] List
val it: int = 10
List of F# 8 new features: https://devblogs.microsoft.com/dotnet/announcing-fsharp-8/