[GHC] #12556: `stimes` adds extra power to Semigroup

#12556: `stimes` adds extra power to Semigroup -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: | Version: 8.0.1 libraries/base | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{ ghci> stimes 0 (undefined :: [_]) [] }}} ghci> stimes 0 undefined () }}} makes it seem like `stimes 0` has some knowledge about `mempty` from `Monoid` but it has the following type {{{#!hs stimes 0 :: Semigroup a => a -> a }}} Desired behaviour? Given that type (assuming it only has the power of `<>`) I would have assumed this behaviour {{{ ghci> data L a = N | C a (L a) deriving Show ghci> instance Semigroup (L a) where (<>) = undefined ghci| ghci> stimes 0 (undefined :: L _) *** Exception: stimes: positive multiplier expected }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12556 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12556: `stimes` adds extra power to Semigroup -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: @@ -4,1 +4,1 @@ - }}} + New description: {{{ ghci> stimes 0 (undefined :: [_]) [] ghci> stimes 0 undefined () }}} makes it seem like `stimes 0` has some knowledge about `mempty` from `Monoid` but it has the following type {{{#!hs stimes 0 :: Semigroup a => a -> a }}} Desired behaviour? Given that type (assuming it only has the power of `<>`) I would have assumed this behaviour {{{ ghci> data L a = N | C a (L a) deriving Show ghci> instance Semigroup (L a) where (<>) = undefined ghci| ghci> stimes 0 (undefined :: L _) *** Exception: stimes: positive multiplier expected }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12556#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12556: `stimes` adds extra power to Semigroup -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): This probably needs to be discussed in the libraries mailing list. I agree this is a bit weird. If `sconcat` takes a `NonEmpty` as argument, then maybe `stimes` should take a `NonZero`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12556#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12556: `stimes` adds extra power to Semigroup -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): It doesn't seem like a problem to me if a particular `Semigroup`'s `stimes` is more defined than the default definition would be, as long as that extension is reasonable, i.e., a monoid homomorphism. Even allowing negative arguments would be reasonable if the `Semigroup` happens to be a group. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12556#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12556: `stimes` adds extra power to Semigroup -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by chris-martin): I see three options: 1. Add a `Semigroup` law "`stimes 0 x` = ⊥". This would require introducing some strictness on the first argument and changing some (many?) instances. 2. Add a `Semigroup` law "If `stimes 0 x` = `i` ≠ ⊥, then `i` must be an identity". I'd guess all of the instances already adhere to this. 3. Add a `Semigroup` "un-law" that simply warns "For `n` less than 1, `stimes n x` is not defined and may produce anything." This certainly requires no code changes. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12556#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC