[Haskell-cafe] Monad instance for Data.Set
oleg at okmij.org
oleg at okmij.org
Tue Mar 25 00:19:37 EDT 2008
The following code solves exactly the problem of implementing
(restricted) MonadPlus in terms of Data.Set:
http://okmij.org/ftp/Haskell/DoRestrictedM.hs
The code is written to demonstrate the do-notation. We write the
monadic code as usual:
> test1s_do () = do
> x <- return "a"
> return $ "b" ++ x
and then instantiate it for Maybe String:
> test1sr_do :: Maybe String
> test1sr_do = unRM $ test1s_do ()
> -- Just "ba"
or for Data.Set:
> test2sr_do :: Set.Set String
> test2sr_do = unSM $ test1s_do ()
> -- fromList ["ba"]
It seems GHC 6.10 will support the do-notation even for the
generalized monads.
More information about the Haskell-Cafe
mailing list