liveBook · Manning

GeneralizedNewtypeDeriving

As explained in Learn Haskell by Example

GeneralizedNewtypeDeriving is a Haskell language extension that derives instances for a newtype from instances of its underlying type.

GeneralizedNewtypeDeriving lets a newtype derive additional type-class instances from its underlying type. Without it, the newtype strategy only covers Eq, Ord, Enum, and Bounded; enabling it also supports classes such as Semigroup and Monoid. section 15.1.2

Deriving instances for a log

A log can wrap a list of entries while reusing the list's Semigroup and Monoid behavior: newtype Log = Log [LogEntry] deriving stock (Show, Eq) deriving newtype (Semigroup, Monoid). The resulting Log can serve as accumulated output for WriterT. section 15.1.2

How Learn Haskell by Example covers it

How deep it goes
Explains the extension through pragmas and a complete Log declaration, but does not detail compiler derivation internals.
Examples
Demonstrates a Log wrapper around [LogEntry] and derives Show, Eq, Semigroup, and Monoid.
What you can do after
Build reusable newtype wrappers that obtain additional instances and work as WriterT accumulated output.
How it connects
Connects newtype deriving with deriving strategies, Semigroup, Monoid, and WriterT.

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.