[Haskell-cafe] Monad instance for Data.Set, again
Ryan Ingram
ryani.spam at gmail.com
Fri Mar 28 21:19:49 EDT 2008
On 3/28/08, Dan Weston <westondan at imageworks.com> wrote:
> I'm having trouble embedding unconstrained monads into the NewMonad:
> Is there some trick (e.g. newtype boxing/unboxing) to get all the
> unconstrained monads automatically instanced? Then the do notation could
> be presumably remapped to the new class structure.
The usual trick here is to use newtypes. (Yes, it sucks)
> newtype OldMonad m = OldMonad m
> unwrapMonad :: OldMonad m -> m
> unwrapMonad (OldMonad m) = m
> instance Monad m => Suitable (OldMonad m) v where
> data Constraints (OldMonad m) v = NoConstraints
> constraints _ = NoConstraints
> instance Monad m => NewMonad (OldMonad m) where
> newReturn = OldMonad . return
> newBind x k = OldMonad $ unwrapMonad x >>= unwrapMonad . k
More information about the Haskell-Cafe
mailing list