haskell / aeson

A fast Haskell JSON library
Other
1.26k stars 321 forks source link

Missing `Monad(fail)` for Parser? #263

Closed hvr closed 9 years ago

hvr commented 9 years ago

While testing the MonadFail patches I've noticed (since they trigger warnings/errors) that in Data.Aeson.Types.Internal there's a Monad-instance lacking a custom fail method implementation:

-- | The result of running a 'Parser'.
data Result a = Error String
              | Success a
                deriving (Eq, Show, Typeable)

instance Monad Result where
    return = Success

    Success a      >>= k = k a
    Error path err >>= _ = Error path err

even though an obvious implementation may be fail = Error

However, the following code fragments refer to fail explicitly, resulting in partial definitions:

instance MonadPlus Result where
    mzero = fail "mzero"
    mplus a@(Success _) _ = a
    mplus _ b             = b
instance Monoid (Result a) where
    mempty  = fail "mempty"
    mappend = mplus

...was this an oversight or deliberate?

/cc @quchen

bos commented 9 years ago

Looks like a mistake to me. Thanks for flagging it.