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

Newtype

Lean: Hale.Base.Newtype | Haskell: Data.Monoid / Data.Semigroup

Overview

Monoid/semigroup wrappers: Dual, Endo, First, Last, Sum, Product, All, Any. Each wraps a value and provides an Append instance with specific combining semantics.

API Mapping

LeanHaskellKind
DualDualWrapper
EndoEndoWrapper
FirstFirstWrapper
LastLastWrapper
Sum / Sum.getSumSum / getSumWrapper
Product / Product.getProductProduct / getProductWrapper
AllAllWrapper
AnyAnyWrapper

Instances

All wrappers provide Append.

WrapperBEqOrdReprHashableToString
Dualyesyesyesyesyes
Sumyesyesyesyesyes
Productyesyesyesyesyes
Allyesyesyesyesyes
Anyyesyesyesyesyes
Firstyesyesyes
Lastyesyesyes
Endo

Proofs & Guarantees

  • append_assoc — associativity of Append for each wrapper

Example

-- Sum combines via addition
Sum.mk 3 ++ Sum.mk 4
-- => Sum 7