Text I/O library proposal, first draft

Ben Rudiak-Gould benrg@dark.darkweb.com
Thu, 31 Jul 2003 23:19:48 -0700 (PDT)


On Fri, 1 Aug 2003, Glynn Clements wrote:

> Ben Rudiak-Gould wrote:
> 
> > -- A BlockRecoder takes source and destination buffers and does some sort
> > -- of translation between them. It returns the number of values (not
> > -- bytes!) consumed and the number of values produced. It does not have to
> > -- empty the input buffer or fill the output buffer on each call, but it
> > -- must do something (i.e. it's not acceptable to return (0,0)). Coders
> > -- will in general have internal state which is updated on each call.
> 
> It would be preferable if this wasn't all within the IO monad. It
> shouldn't be necessary, even for stateful encodings.

The problem is that all the Ptr access functions are in the IO monad.
Switching to a different monad would require the use of unsafePerformIO or
unsafeIOtoST, and I couldn't see any obvious way to guarantee safety. It
seems better for the library user to make the unsafe conversions
explicitly if they're to be made at all.

The other possibility would be to drop the Ptrs and use STUArrays or
immutable data structures, but I think that would inevitably be less
efficient (especially given that many/most text coders are likely to be
implemented using libc functions), and the standard text I/O library needs
to be efficient.

-- Ben