_______________________________________________David,
I tried your first suggestion $!. Nothing changed.
When I tried ‘Right <$> evaluate (TE.decodeUtf8 bufferStrict)’ success. handleException catches the exception.
I don’t understand why. Maybe the documentation for the evaluate function below has to do with it:
There is a subtle difference between
evaluatexandreturn$!x, analogous to the difference betweenthrowIOandthrow. If the lazy valuexthrows an exception,return$!xwill fail to return anIOaction and will throw an exception instead.evaluatex, on the other hand, always produces anIOaction; that action will throw an exception upon execution iffxthrows an exception upon evaluation.I don’t fully understand this, but evaluate works. Thanks!
Kees
readCDFile :: FilePath -> FilePath -> IO (Either String T.Text)
readCDFile baseDir fn = do
catch ( do
buffer <- B.readFile (combine baseDir fn) --reads strict the whole file
let bufferStrict = B.toStrict buffer
return $ Right $! TE.decodeUtf8 bufferStrict -- this doesn’t work
Right <$> evaluate (TE.decodeUtf8 bufferStrict) –- this does
liftM Right $ evaluate (TE.decodeUtf8 bufferStrict) – this works too
) exceptionHandler
Van: David Fox [mailto:dsf@seereason.com]
This fixes it by forcing the evaluation of the decode where it can be caught:
return $ Right $! TE.decodeUtf8 bufferStrict
or
Right <$> evaluate (TE.decodeUtf8 bufferStrict)
<snip>
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.