Created
April 1, 2012 03:30
-
-
Save skyscribe/2270970 to your computer and use it in GitHub Desktop.
New haskell exception ambiguous type issue in real word example code BetterPredicate.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Exception (bracket, handle, SomeException) | |
import System.IO (IOMode(..), hClose, hFileSize, openFile) | |
{-- snippet getFileSize --} | |
-- To work around the code that doesn't work in Haskell 6.10 | |
-- Control.Exception is changed to allow ploymophism such that | |
-- handle (\_ -> return Nothing) doesn't compile | |
hdl::SomeException -> IO (Maybe a) | |
hdl _ = return Nothing | |
--getFileSize path = handle (\_ -> return Nothing) $ | |
getFileSize path = handle (hdl) $ | |
bracket (openFile path ReadMode) hClose $ \h -> do | |
size <- hFileSize h | |
return (Just size) | |
{-- /snippet getFileSize --} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aslo check links in this thread in stackoverflow