Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Compose

Lean: Hale.Base.Compose | Haskell: Data.Functor.Compose

Overview

Composition of functors/applicatives. Compose F G a wraps F (G a), allowing two functors to be composed into a single functor (or two applicatives into a single applicative).

API Mapping

LeanHaskellKind
ComposeComposeType
getComposegetComposeAccessor

Instances

  • Functor (Compose F G) (requires Functor F, Functor G)
  • Pure (Compose F G) (requires Applicative F, Applicative G)
  • Seq (Compose F G) (requires Applicative F, Applicative G)
  • Applicative (Compose F G) (requires Applicative F, Applicative G)

Proofs & Guarantees

  • map_idFunctor.map id = id (with lawful functors)
  • map_compFunctor.map (f . g) = Functor.map f . Functor.map g (with lawful functors)

Example

-- Compose List and Option into a single functor
Compose.mk [some 1, none, some 3]
-- : Compose List Option Nat