[GHC] #11650: Documentation does not mention that default definitions for Alternative(some, many) can easily blow up
GHC
ghc-devs at haskell.org
Fri Feb 26 12:02:46 UTC 2016
#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:
@@ -45,3 +45,2 @@
- 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
+ should note this in the documentation to ensure that users don't end up
+ with accidentally bottoming instances.
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 note this in the documentation to ensure that users don't end up
with accidentally bottoming instances.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11650#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list