[Haskell-cafe] Restricted file reading monad

Bryan O'Sullivan bos at serpentine.com
Thu Oct 2 16:45:12 EDT 2008

2008/10/1 George Pollard <porges at porg.es>:

> Since the ID3 tag as a whole has size information, I need to pass that
> into the frame-reading functions to ensure that I never read past the
> end of the total header.

What you want for this is the environment monad, also known as the
Reader monad in Haskell. It gives you something similar to a piece of
read-only global state. For this application, you'd pass in two pieces
of state: the file handle to read, and the limit on the number of
bytes that a client can read.

Since we can't easily combine the normal Reader monad and IO, we use a
monad transformer stack.

I've attached an example for your amusement.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ReadHelper.hs
Type: application/octet-stream
Size: 1475 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20081002/3982e87b/ReadHelper.obj

More information about the Haskell-Cafe mailing list