liveBook · Manning

Type lambda

As explained in Functional Programming in Scala, Second Edition

A type lambda is an anonymous type-level function that maps type arguments to a constructed type.

A type lambda is an anonymous type-level function: it accepts a type argument and returns a constructed type. In State[Int, _], the fixed state type is Int while the result type remains variable. section 11.5.2

Partially applying State

The explicit form [x] =>> State[Int, x] describes a constructor from x to State[Int, x]. Scala can use it directly in a Monad instance: Monad[[x] =>> State[Int, x]]. With -Ykind-projector:underscores enabled, State[Int, _] provides the abbreviated form. Generalizing Int to S yields a monad for every state type. section 11.5.2

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Defines the construction, contrasts full and abbreviated syntax, and applies it to a generic State monad instance.
Examples
Shows State[Int, _], [x] =>> State[Int, x], and a generic stateMonad[S] declaration.
What it assumes
Assumes State, type constructors, and Monad while making anonymous type-constructor syntax concrete through State examples.
What you can do after
Apply it via Scala type-lambda syntax to declare Monad instances for partially applied State constructors.
How it connects
Connects type lambdas with State, partial type application, anonymous type constructors, and Monad.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.