On Tue, Dec 18, 2007 at 09:51:02AM +0000, Simon Marlow wrote:
> Stefan O'Rear wrote:
>
>> How about something like:
>>
>> data Cookie = C { getData :: L.ByteString }
>> fetchURL :: URI -> Cookie -- sends request when forced, reads
>> responce when deeply forced
>>
>> {- sample implementation, ignores the existance of multiple servers and
>> the Connection: close header -}
>>
>> sock = unsafePerformIO ...
>>
>> queue fun = newChan >>= \q -> forkIO (forever (readChan q >>= fun)) >>
>> return q
>>
>> writer = unsafePeformIO $ queue $ \ req -> writeRequest sock req
>> reader = unsafePeformIO $ queue $ \ var ->
>> readRequest sock (\ bit -> writeChan var (Just bit)) >>
>> writeChan var Nothing
>>
>>
>> fetchURL url = unsafePerformIO $ do
>> c <- newChan
>> writeChan writer (fetch url)
>> writeChan reader c
>
> A single queue seems nicer, given that you would otherwise need some
> locking to prevent races between multiple threads (I know this doesn't
> apply to darcs, but still).The code was intended only to clarify the semantics of the interface. Stefan
signature.asc
Description: Digital signature
_______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
