[Haskell-cafe] External system connections

Felipe Almeida Lessa felipe.lessa at gmail.com
Mon Jul 11 17:41:23 CEST 2011


On Mon, Jul 11, 2011 at 12:27 PM, Michael Orlitzky <michael at orlitzky.com> wrote:
> How do people use this stuff? The README is empty, there's no
> documentation, and none of the functions are commented. I'm forced to
> conclude that there are people capable of looking at this,
>
>  createPoolCheckAlive :: MonadControlIO m
>                          => IO a
>                          -> (a -> IO ())
>                          -> Int
>                          -> (Pool a -> m b)
>                          -> (a -> IO Bool)
>                          -> m b
>
> and knowing immediately what it does.

Yes, there's a documentation problem.  But you can guess by the types =).

IO a: opens a new resource a.
a -> IO (): disposes the given resource.
Int: maximum number of open resources.
Pool a -> m b: the action you want to execute; after it executes, the
pool is destroyed.
a -> IO Bool: check if the resource is still alive.
m b: the result of running your given action with a new pool.

The key to understanding all of this is looking backwards from the result.

1) The result is m b.  Where did this come from?
2) Well, there's a 'Pool a -> m b'.  So it runs the action for me.  So
this is like a 'withFile :: FilePath -> (Handle -> IO a) -> IO a'
function.
3) So if it is a 'Pool a', then the resource is of type 'a'.
4) The only function returning 'a' is 'IO a', so this creates the resource.
5) By the same reason, 'a -> IO ()' disposes it.
6) 'a -> IO Bool' is confusing, but there's a doc for that.
7) 'Int' is also confusing, but since this is a pool, this must be the
maximum number of open resources.

HTH,

-- 
Felipe.



More information about the Haskell-Cafe mailing list