[Haskell-cafe] The rmonad package is mysterious

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


Hi,

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:

http://hackage.haskell.org/package/suitable-0.1.1/docs/Data-Suitable.html

http://hackage.haskell.org/package/rmonad-0.8.0.1/docs/Control-RMonad.html

(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)

Cheers,

Ganesh


More information about the Haskell-Cafe mailing list