[Haskell-cafe] Iteratee, parsec & co.
Valery V. Vorotyntsev
valery.vv at gmail.com
Tue Feb 9 10:08:48 EST 2010
| 3. Why Seek FileOffset is error message?
Are you talking about John Lato's implementation ?
Well, `Seek' is not an error message. It is one of constructors for
ErrMsg, and ErrMsg is 
> -- -- a message to the stream producer (e.g., to rewind the stream)
> -- or an error indication.
You know the overall idea behind Seek, don't you? It is an instrument
to implement random IO .
Compare Oleg's code 
> data SeekException = SeekException FileOffset
> deriving Show
> instance Typeable SeekException where
> typeOf _ = mkTyConApp (mkTyCon "SeekException") 
> instance Exception SeekException
> type ErrMsg = SomeException
> data Stream el = EOF (Maybe ErrMsg) | Chunk [el] deriving Show
with John Lato's implementation :
> data StreamG c el =
> EOF (Maybe ErrMsg)
> | Chunk (c el)
> data ErrMsg = Err String
> | Seek FileOffset
> deriving (Show, Eq)
John makes Err and Seek to be the distinct constructors of ErrMsg.
Errors (Err) in `iteratee' package are always Strings.
Oleg's ErrMsg is SomeException. One of its instances (SeekException)
is a ``rewind the stream'' message to the stream producer. And the user
is free to have as many different ErrMsg'es as he needs to do the job.
More information about the Haskell-Cafe