jonnifyfsharp

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

C1.01.1 primitive types C1.01.2 type inference C1.01.3 F# Interactive the values the tool
C1.01.1 · Primitive types & literals

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.

You learn how to write every primitive and read its type

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.

live module hub built dive ready soon specified

References

Sources

Related in this course