Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,248
    • Issues 4,248
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 391
    • Merge Requests 391
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17859

Closed
Open
Opened Feb 21, 2020 by jackkelly@trac-jackkelly

instance Semigroup/Monoid (f (g a)) => Semigroup/Monoid (Compose f g a)

Motivation

I am defining a higher-kinded data structure representing configuration:

data Config f = Config
  { _port :: f Int
  , _db :: f FilePath
  }

instance (forall a . Semigroup (f a)) => Semigroup (Config f) where
  Config p1 db1 <> Config p2 db2 = Config (p1 <> p2) (db1 <> db2)

instance (forall a . Monoid (f a)) => Monoid (Config f) where
  mempty = Config mempty mempty

I want to represent partial configs using the Maybe (Last a)) Monoid. To make that fit, I have to use Data.Functor.Compose.Compose:

type FullConfig = Config Identity
type PartialConfig = Config (Compose Maybe Last)

However, Compose f g a has no Monoid instance that uses the underlying f (g a). At this point I am sad, and have to either write an orphan, or my own newtype Last a = Last (Maybe a) which is the same as Data.Maybe.Last (which was meant to be deprecated in 8.8, according to base-4.13.0.0 haddocks?).

Proposal

Add the following instances (possibly GeneralizedNewtypeDeriving will give them to us):

instance Semigroup (f (g a)) => Semigroup (Compose f g a)
instance Monoid (f (g a)) => Monoid (Compose f g a)

Related Issues

#15028 - Deprecate and remove Data.Semigroup.Option; Data.Monoid.{First,Last}
#16636 - Eq1/Show1 etc for Data.Monoid.{First,Last}

Edited Feb 21, 2020 by jackkelly
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#17859