Core Types

"I keep six honest serving-men: / (They taught me all I knew) / Their names are What and Where and When / And How and Why and Who."

— Rudyard Kipling, Just So Stories (The Elephant's Child)


Each family asks one of them of a value: what, if anything, it holds; why it failed; when it runs; where its settings come from; how many there are; or who runs it.

A core type holds a value, as Java's Optional does, and the library adds its own. Application code reaches most of them through an Effect Path, and generic code through type class instances; the Foundations introduction says which you are writing.

Read a page when a task needs its type, and skip the group until then. Choosing a Type and What each type supports help you choose.


Pages in this group

  • Failure
  • Absence
    • Maybe: A value, or nothing, and never null
    • Optional: Java's Optional, with the same instances as Maybe
  • Deferred
    • IO: A side effect described now and run later
    • Lazy: A value worked out when first asked for, then kept
    • CompletableFuture: Java's asynchronous result, already running
  • Virtual threads
  • Environment and state
    • Reader: A value worked out from settings
    • Context: Request values bound to a ScopedValue
    • State: A step that reads a state and gives a new one
    • Writer: A value with a log beside it
  • Collections
    • List: Java's List, read as many possible results
    • Stream: Java's Stream, each element worked out when needed
  • Programs as data
    • Identity: A value and nothing else, for generic code with no effect
    • Trampoline: A recursion that runs without growing the stack
    • Free: A program written as data, for an interpreter to run
    • Free Applicative: Independent steps an interpreter can inspect before running them
    • EitherF: Two instruction sets joined, so one program can use both
    • Coyoneda: A Functor for any type, which joins its map calls into one
    • Const: A value of its first type and none of its second, for folds and getters

Hands-On Learning

Practise the core types together in Tutorial 07: Real World (6 exercises).


Previous: ForState Comprehension Next: Either