Skip to content
let Bindings and Type Inference
step 1/5

Reading — step 1 of 5

Learn

~1 min readFirst Steps

let binds a name to a value. Bindings are immutable by default:

let name = "Ada"
let age = 36
let pi = 3.14159

F#'s type inference is exceptional. The compiler infers types from usage — you almost never annotate.

When you DO want to annotate:

let age: int = 36
let greet (name: string) : string = sprintf "Hello, %s!" name

For mutable bindings, use let mutable and assign with <- (NOT =):

let mutable counter = 0
counter <- counter + 1

Reading stdin: System.Console.ReadLine(). Parse: int(s), float(s). Both return values; failures throw.

let n = int(System.Console.ReadLine())

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…