[Haskell] Re: [Haskell-cafe] ANNOUNCE: enumerator, an alternative
iteratee package
John Millikin
jmillikin at gmail.com
Sun Aug 22 11:11:54 EDT 2010
On Sat, Aug 21, 2010 at 23:14, Paulo Tanimoto <ptanimoto at gmail.com> wrote:
> One question: enumFile has type
>
> enumFile :: FilePath -> Enumerator SomeException ByteString IO b
>
> and iterParser has type
>
> iterParser :: Monad m => Parser a -> Iteratee ParseError ByteString m a
>
> How do we use both together? Something in these lines won't type-check
>
> E.run (E.enumFile "file" E.$$ (E.iterParser p))
>
> because the error types are different.
Forgot to mention that -- use the "mapError" function from
enumerator-0.2.1 thusly:
http://ianen.org/haskell/enumerator/api-docs/Data-Enumerator.html#v%3AmapError
--------------------------------------------------------------------------------
parser :: Parser Foo
toExc :: Show a => a -> E.SomeException
toExc = E.SomeException . E.ErrorCall . show
main :: IO ()
main = do
run (enumFile "parsetest.txt" $$ mapError toExc $$ iterParser parser) >>= print
--------------------------------------------------------------------------------
You don't have to map to SomeException -- any type will do. For
example, in a complex pipeline with real error handling at the other
end, you might want a custom error type so you'll know at what stage
the error occurred.
More information about the Haskell-Cafe
mailing list