[Haskell-cafe] MonadList?

Michael Shulman viritrilbia at gmail.com
Wed Sep 13 16:52:41 EDT 2006


In another thread, I wrote:
> main = (>> return ()) $ runListT $ do
>         arg <- ListT getArgs
>         n <- ListT $ return [1..3]
>         liftIO $ putStrLn ((show n) ++ ") " ++ arg)

The frequent occurence of "ListT $ return" in my code when I use the ListT
monad transformer has made me wonder why there isn't a standard typeclass
`MonadList', like those for the other monad transformers, encapsulating
the essence of being a "list-like" monad -- in this case, the ability to
select from a list of things.  I quickly wrote one for myself:

class MonadList m where
    option :: [a] -> m a

instance MonadList [] where
    option = id

instance (Monad m) => MonadList (ListT m) where
    option = ListT . return

Has anyone else thought about or done something like this?

Mike


More information about the Haskell-Cafe mailing list