[Haskell-cafe] Stream processors

Ben Rudiak-Gould br276 at cl.cam.ac.uk
Thu Oct 21 11:08:08 EDT 2004


Peter Simons wrote:

>  type Buffer = (Ptr Word8, Int)
>
>  data StreamProc ctx a
>    = SP
>      { start  :: IO ctx
>      , feed   :: ctx -> Buffer -> IO ctx
>      , commit :: ctx -> IO a
>      }
>  
>
Must contexts be used in a single-threaded manner? If so, I would expect 
this interface:

    start  :: IO ctx
    feed   :: ctx -> Buffer -> IO ()
    commit :: ctx -> IO a

If not, I would expect this interface:

    start  :: ctx
    feed   :: ctx -> Buffer -> IO ctx
    commit :: ctx -> a

Additionally, I don't think (Ptr Word8, Int) is general enough for all reasonable uses of this interface. For example, there's nothing inherently unsafe about calculating the MD5 hash of the contents of an STUArray or UArray:

    feedBuffer   :: ctx -> Buffer               -> IO ctx
    feedSTUArray :: ctx -> STUArray s Int Word8 -> ST s ctx
    feedUArray   :: ctx -> UArray Int Word8     -> ctx

And what about a subrange of an STUArray or UArray? These are the problems I ran into when trying to produce a useful MD5 library for Haskell. I feel the same way as you -- that there should be a standard way of doing this -- but I don't think the three functions you propose are nearly enough.

-- Ben




More information about the Haskell-Cafe mailing list