[GHC] #12372: bug: documentation for Control.Monad.guard not useful after AMP
GHC
ghc-devs at haskell.org
Wed Aug 31 06:09:12 UTC 2016
#12372: bug: documentation for Control.Monad.guard not useful after AMP
-------------------------------------+-------------------------------------
Reporter: ntc2 | Owner:
Type: bug | Status: infoneeded
Priority: normal | Milestone:
Component: libraries/base | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Documentation | Unknown/Multiple
bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by ntc2):
Replying to [comment:4 bgamari]:
> ntc2, any word on this?
So, I'm only familiar with `MonadPlus` examples. E.g.
{{{
safeDivision :: (Eq a, Fractional a, MonadPlus m) => a -> a -> m a
safeDivison n d = do
guard (d /= 0)
return (n / d)
ghci> safeDivision 3 0 :: Maybe Double
Nothing
ghci> safeDivision 3 2 :: Maybe Double
Just 1.5
}}}
Now, it turns out I can also write that example using `Alternative`, i.e.
{{{
safeDivisionA :: (Eq a, Fractional a, Alternative f) => a -> a -> f a
safeDivisionA n d = guard (d /= 0) *> pure (n / d)
ghci> safeDivisionA 3 0 :: Maybe Double
Nothing
ghci> safeDivisionA 3 2 :: Maybe Double
Just 1.5
}}}
but the default `Alternatives` I know are exactly the `MonadPlus` types,
i.e. `[]` and `Maybe`, so I don't see what I've gained here (and in
practice I think I'd just use `Maybe` here).
So, I think a `MonadPlus` example like `safeDivision` would be useful.
An example that only makes use of the weaker `Alternative` assumption
might also be useful, but I don't have one.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12372#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list