
2 Oct
2008
2 Oct
'08
4:45 p.m.
2008/10/1 George Pollard
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.