[GHC] #15182: Lazier Semigroup instance for Maybe

#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

#15182: Lazier Semigroup instance for Maybe -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by oerjan): * cc: oerjan (added) Comment: The last version is ''not'' equivalent - it doesn't produce `Just` until the right argument has been evaluated. For example, with the former, I think `foldMap (Just . (:[])) [1..] = Just [1..]`, but with the latter (and with the current one) it diverges. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15182#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC