Frank Christoph wrote:
> One other thing: you need overlapping instances to partially instantiate the
> monad transformer so you can define things like:
>
> > class (Monad m) => STM m where
> > update :: (String -> String) -> m String
> > set :: String -> m String
> > fetch :: m String
> > set s = update (\_ -> s)
> > fetch = update id
> vvvvvv
> > instance (Monad m) => STM (StateM m String) where
> > update f = StateM (\s -> return (s, f s))
More seriously, you need to give a separate instance declaration for every
state used in the program, even though the "update" method is implemented
exactly the same way. This also makes monad transformers unsuitable for use
in a library, where it's unknown what built-in or user-defined types will
later be used as a state.
Regards,
Sheng Liang