liveBook · Manning

Static typing

As explained in Functional Design and Architecture: Examples in Haskell

A statically typed language checks the types of program constructs before execution, typically during compilation.

Static typing moves important correctness checks into program design: an expressive type system and compiler can reject invalid constructions before execution, reducing reliance on step-by-step debugging. section 1.5.2

The technique becomes especially valuable when types describe domain rules. Algebraic data types and pattern matching can make valid cases explicit, while the compiler catches calls that do not match the declared model. section 1.5.2 section 5.1

Static typing supports several design goals:

  • Catch classes of errors before running the program, including passing an integer where a Shape is required. section 1.5.2
  • Make domain operations safer by restricting programs to correct states and permitted operations. section 5.1
  • Support functional design alongside purity, algebraic data types, type classes, and higher-kinded types. section 1.5.1 section 5.1

A typed shape function

Define Shape with Circle and Rectangle constructors, then declare area :: Shape -> Double. Calling area with 5 produces a compiler error because Integer does not match Shape. The type declaration and pattern matches expose the intended domain cases directly. section 1.5.2

data Shape = Circle Double
          | Rectangle Double Double

Browse the Shape algebraic data type, its area function, an invalid call, and the resulting compiler diagnostic. section 1.5.2

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Explains compiler-gated error classes and domain modeling with algebraic data types, but does not detail type-system implementation internals.
Examples
Uses Shape and area definitions, an invalid area call, a compiler mismatch, and measurement-unit errors as examples.
What it assumes
Assumes familiarity with functions and programming, while introducing compile-time guarantees through a concrete algebraic data type example.
What you can do after
Evaluate and design domain models that let compilers reject mismatched operations before execution.
How it connects
Connects static typing with functional programming, purity, algebraic data types, type classes, higher-kinded types, and domain-specific languages.

Also explained in

Compare how 12 books explain static typing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.