[Haskell-cafe] Generalizing IO

David Menendez dave at zednenem.com
Mon Oct 5 20:23:35 EDT 2009

On Mon, Oct 5, 2009 at 7:56 PM, Floptical Logic <flopticalogic at gmail.com> wrote:
> The code below is a little interactive program that uses some state.
> It uses StateT with IO to keep state.  My question is: what is the
> best way to generalize this program to work with any IO-like
> monad/medium?  For example, I would like the program to function as it
> does now using stdin but I would also like it to function over IRC
> using the Net monad from
> <http://haskell.org/haskellwiki/Roll_your_own_IRC_bot>.  Thanks for
> any suggestions.

Instead of specifying the monad implementation, specify the interface.
That is, you are using state operations (from MonadState) and IO
operations (from MonadIO). Try removing all the type signatures that
mention PDState and see what you get.

E.g., loop :: (MonadState PD m, MonadIO m) => m a

Dave Menendez <dave at zednenem.com>

More information about the Haskell-Cafe mailing list