Module C1.01
Values, types & FSI
Every value carries a type the compiler works out, and one tool to put both under a microscope.
F# is a statically typed language with a difference: the types are almost always
there, and a programmer almost never writes them. A value such as 42 is an
int; 3.14 is a float;
"F#" is a string — and the compiler reads the type off the
literal or the use. The tool that makes this visible is FSI, F# Interactive: type an
expression, end it with ;;, and FSI prints back the value and its type. This module
covers the foundation in three dives — the primitive types and how to write their literals, the inference that
assigns a type to every binding, and the FSI session where you can watch it happen.
The foundation, in three dives
Before a single function, F# rests on two facts: a value has a type, and the compiler can find that type on its own. The three dives below build that floor. Select one to read its summary and the one idea it adds.
The first dive names the built-in types — int,
float, bool, char,
string, unit, and their siblings — and the literal forms
that produce them. The second covers type inference: F# reads a type for every binding from
the surrounding use, generalising to the most general type where it can. The third is FSI,
the REPL that prints val it : <type> = <value> for whatever you give
it — the fastest way to confirm any claim on this page.
The three dives · select one
The built-in types and the literal forms that produce them: 42 is an int, 3.14 a float, 'a' a char, "hi" a string, () the one value of unit.
Open this dive · or pick another above
A type for every value, and one REPL to print it back. That floor holds up everything F# builds on top.
The three dives
Read them in order. Each stands on valid, runnable F#: every literal, every inferred type, and every FSI
line below can be typed into dotnet fsi and produces exactly what the page shows.
Primitive types & literals
int, float, bool, char, string, unit, and the literal forms — hex, separators, suffixes, interpolation.
- valueswrite every primitive, read its type
Type inference
How F# assigns a type to every binding from its use, and generalises to the most general type.
- typesthe constraint that pins each type
F# Interactive
The REPL: terminate with ;;, read val it, load scripts, time code.
- toolthe read-eval-print loop, step by step
References
Sources
- Microsoft — F# documentation — the language guide: literals, primitive types, and type inference.
- The F# Language Specification — the precise grammar for literals, types, and inference.
- The F# Software Foundation — the language's home and its tooling, including FSI.
Related in this course
- C1.01.1 — Primitive types & literals — the built-in types and how to write them.
- C1 — F# Language — the chapter this module opens.
- Elixir — Values — the same foundation, told for the BEAM.