liveBook · Manning

Target monad

As explained in Functional Programming in Scala, Second Edition

A target monad is the monadic computation type into which an effect program is directly constructed or interpreted for execution.

A target monad is the monadic computation type into which an effect program is directly constructed or interpreted for execution. With Free, primitive operations are composed first and later interpreted into a target such as Par or Thunk. Capability traits offer a shorter route: each operation returns an F-valued computation without exposing F's implementation. section 13.6

A target monad supports several design choices:

  • It lets the same effect program remain independent of whether execution uses Par, Function0, or another supported monad. section 13.6
  • It receives primitive operations through capability traits such as Console[F] and Files[F], rather than requiring a free-program encoding. section 13.6

Console capability

A Console[F] can construct F[Option[String]] for reading and F[Unit] for printing. Par and Function0 provide separate implementations, while greet remains polymorphic over F.

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Explains construction, interpretation, capability-based alternatives, and concrete instances, but not target-monad internals.
Examples
Uses Console and Files capabilities, Par and Function0 instances, greeting, and file concatenation.
What it assumes
Assumes familiarity with monads and effect composition while contrasting Free programs with capability-based construction.
What you can do after
Build effect programs polymorphically and interpret or execute them through supplied target-monad instances.
How it connects
Connects target monads with Free, interpreters, monads, effect algebras, and capability traits.

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.