[Haskell-cafe] Re: Stream processors

Peter Simons simons at cryp.to
Thu Oct 21 12:53:33 EDT 2004


Ben Rudiak-Gould writes:

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

 >> 'feed' cannot have this signature because it needs to
 >> update the context.

 > Sure it can -- it's just like writeIORef :: IORef a -> a -> IO ().

I guess it's mood to argue that point. I don't want a stream
processor to have a global state, so using an internally
encapsulated IORef is not an option for me.

I am looking for an more _general_ API, not one that forces
implementation details on the stream processor. That's what
my StreamProc data type does already. :-)


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

 > In this interface contexts are supposed to be immutable
 > Haskell values, so there's no meaning in creating new
 > ones or finalizing old ones.

I don't want to restrict the API to immutable contexts. A
context could be anything, _including_ an IORef or an MVar.
But the API shouldn't enforce that.


 >> I would implement feedSTUArray and friends as wrappers
 >> around the Ptr interface, not as primitive computations of
 >> the stream processor.

 > I think it's impossible to do this safely, but it would be
 > great if I were wrong.

  wrap :: (Storable a, MArray arr a IO) => Ptr a -> Int
       -> IO (arr Int a)
  wrap ptr n = peekArray n ptr >>= newListArray (0,n)

Peter



More information about the Haskell-Cafe mailing list