Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,249
    • Issues 5,249
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 582
    • Merge requests 582
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #10063
Closed
Open
Issue created Feb 03, 2015 by Edward Kmett@ekmett

State a law for foldMap

After being prodded by /u/random_crank on reddit, I realized there is a law we can state for foldMap:

A monoid homomorphism g is a function such that

g mempty = mempty
g (mappend a b) = mappend (g a) (g b)

holds.

For any monoid homomorphism g:

foldMap (g . f) = g . foldMap f

This isn't strictly a free theorem as it relies on the Monoid laws, but it is true and has the same general flavor as the equally complicated free theorem for foldr.

This law is a bit technical, but is a nice tool for equational reasoning, and gives rise to a much nicer foldMap-based version of the "banana split" theorem for foldr.

foldMap f &&& foldMap g = foldMap (f &&& g)
Trac metadata
Trac field Value
Version 7.10.1-rc1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC core-libraries-committee@haskell.org
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking