Skip to content

Instantly share code, notes, and snippets.

@skyscribe
Created April 1, 2012 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyscribe/2270970 to your computer and use it in GitHub Desktop.
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
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 --}
@skyscribe
Copy link
Author

Aslo check links in this thread in stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment