[Haskell-cafe] carry "state" around ....

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Mon Jul 28 03:14:26 EDT 2008

On 2008 Jul 28, at 2:41, Galchin, Vasili wrote:

>      So based on what you are saying I kind of need a Haskell AIO  
> "imperative"/monadic function that basically returns a handle that  
> is associated with this AIOCB chunk-of-memory .... This handle gets  
> passed around during an AIO I/O session?? Sorry for talking too  
> "imperatively" ;^) <<< smiley face ;^)

I/O *is* monadic in Haskell, so you're kinda there anyway.  I would in  
fact use a custom state (AIO = StateT ForeignPtr IO) if I were doing  
it; I would hide the constructor so that the only way to alter values  
is to call specific function(s) returning filled-in aiocbs as  
initialized and passed to aio_read/aio_write, then provide accessors  
for the contents (which if necessary can call aio_return, aio_suspend,  
or aio_error).  Returning from the monad would invoke aio_suspend to  
wait for completion or aio_cancel to abort.  (Hm.  Could be argued  
that we want ContT here to represent the two possibilities.)

I note from my local documentation that (a) indeed you must not modify  
the aiocb after passing it to aio_read/aio_write and (b) the offset  
value should not be read, much less modified, because it could change  
during the async I/O (and not in a reliably useful fashion; consider  
buffering).  And as I said earlier, the exact same memory block (not  
merely a copy of it) must be used for the same aiocb.

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080728/9991851e/attachment.htm

More information about the Haskell-Cafe mailing list