
#15182: Lazier Semigroup instance for Maybe -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Mailing list discussion here: https://mail.haskell.org/pipermail/libraries/2018-May/028818.html The existing `Semigroup` instance for `Maybe` is: {{{ instance Semigroup a => Semigroup (Maybe a) where Nothing <> b = b a <> Nothing = a Just a <> Just b = Just (a <> b) }}} It has been proposed that it be replaced by: {{{ instance Semigroup a => Semigroup (Maybe a) where Nothing <> b = b Just a <> b = Just (maybe a (a<>) b) }}} This is lazier in the second argument, making it more consistent with the strictness of the `Semigroup` instances for `And`,`Or`,`Ord`,`Either`,`Proxy` and `()`. Equivalently, we could write: {{{ instance Semigroup a => Semigroup (Maybe a) where Nothing <> b = b Just a <> Nothing = Just a Just a <> Just b = Just (a <> b) }}} This makes it a little more clear that we aren't building a closure for partial function application, but it should have the same behavior. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15182 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler