[Haskell-cafe] The rmonad package is mysterious

Ganesh Sittampalam ganesh at earth.li
Tue Dec 3 07:58:25 UTC 2013


This is rather late, but in case it's useful:

On 10/04/2013 19:30, Simon Marechal wrote:
> I tried to do something simple using the rmonad package (attached).
> I followed the example that's in haddocks (it is wrong, constraints has
> no arguments), grabbed the list of extensions from rmonad's source, but
> this program doesn't typecheck:
> Could not deduce (Hashable a) arising from a use of `HM.singleton'
> This seems to be an obvious use of this package ... am I missing something ?

The dictionaries for the superclasses are "wrapped up" in the data
constructor MonadOutcome, so you need to unwrap it. For example:

    instance RMonad MonadOutcome where
        return (x :: a) =
            case constraints :: Constraints MonadOutcome a of
                OutcomeConstraints -> MonadOutcome (HM.singleton x 1)

There are helper functions in Data.Suitable for doing this, for example
withResConstraints infers the right 'a' from the inferred result type:

    import Data.Suitable (Constraints, withResConstraints)


    instance RMonad MonadOutcome where
        return x =
            withResConstraints $ \OutcomeConstraints ->
                MonadOutcome (HM.singleton x 1)
        (>>=) = undefined

The documentation on hackage gives signatures and examples:



(note that the Set example doesn't need constraints for 'return' because
Data.Set.singleton doesn't have an Ord constraint, but you can see it in
the >>= implementation)



More information about the Haskell-Cafe mailing list