<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<tt>Hello All,<br>
<br>
I have recently encountered 2 situations where I needed an IO
action, but only had a monad stack with IO at the bottom.<br>
<br>
The two examples were:<br>
<br>
1. from </tt><tt>Control.Concurrent.Async<br>
</tt><tt> withAsync :: IO a -> (Async a -> IO b) -> IO b
<br>
<br>
2. from Network.WebSockets</tt><br>
<tt>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
runClient :: String -- ^ Host<br>
-> Int -- ^ Port<br>
-> String -- ^ Path<br>
-> (</tt><tt>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
Connection -> IO a) -- ^ Client application<br>
-> IO a<br>
<br>
I need to pass a function that returns an IO action to both these
functions.<br>
I think my life would be easier if the function signatures were:<br>
<br>
</tt><tt><tt>1. withAsync :: MonadIO mIO => mIO a -> (Async a
-> </tt></tt><tt><tt><tt><tt>mIO</tt></tt> b) -> </tt></tt><tt><tt><tt><tt>mIO</tt></tt>
b <br>
<br>
2. from Network.WebSockets</tt><br>
<tt> runClient :: </tt></tt><tt><tt><tt><tt>MonadIO mIO =><br>
</tt></tt> -> String -- ^ Host<br>
-> Int -- ^ Port<br>
-> String -- ^ Path<br>
-> (</tt><tt>Connection -> mIO a) -- ^ Client
application<br>
-> mIO a<br>
</tt><br>
There are many other examples, a notable one are the functions in
Control.Exception also always expect an IO action.<br>
I know we have libraries to solve this problem, such as
lifted-async, lifted-base and the functionality in
Control.Monad.Trans.Control.</tt><br>
<tt>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
But what are the best practices for writing code that uses Monadic
actions? Should I always generalize my type signatures or just
expect others to use the libraries when they need to?<br>
<br>
Also, to some extent it seems trivial to re-write a library like
async with the generalized signatures I need. I would just need to
apply 'lift' everywhere. Couldn't the compiler do this for me? ;-)<br>
<br>
<br>
Thanks,<br>
<br>
<br>
Dimitri<br>
<br>
<br>
<br>
</tt><br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
</body>
</html>