
#11650: Documentation does not mention that default definitions for Alternative(some, many) can easily blow up -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Documentation | Version: 7.10.3 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: | -------------------------------------+------------------------------------- Description changed by bgamari: @@ -30,0 +30,10 @@ + Of course, this can be avoided by simply defining `some` and `many` in + `U1`'s `Alternative` instance, + {{{#!hs + instance Alternative U1 where + empty = U1 + U1 <|> U1 = U1 + some U1 = U1 + many U1 = U1 + }}} + New description: Consider this case (taken from #11649) {{{#!hs import Control.Applicative data U1 p = U1 instance Functor U1 where fmap f U1 = U1 instance Applicative U1 where pure _ = U1 U1 <*> U1 = U1 instance Alternative U1 where empty = U1 U1 <|> U1 = U1 instance Show (U1 p) where show U1 = "U1" main = print (some U1) }}} This looks fine, right? Wrong, {{{ $ ./Main Main: <<loop>> }}} Of course, this can be avoided by simply defining `some` and `many` in `U1`'s `Alternative` instance, {{{#!hs instance Alternative U1 where empty = U1 U1 <|> U1 = U1 some U1 = U1 many U1 = U1 }}} It seems that the default definitions of `some` and `many` will produce looping code in these cases (although it's not entirely clear to me which cases "these" cases are). I suppose this is due to the fact that `U1` will always "succeed". We should ensure that this is noted in the documentation to ensure that users don't end up with accidentally bottoming instances. Well, consider what happens -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11650#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler