Skip to content

Instantly share code, notes, and snippets.

@joshcough
Created June 25, 2014 01:25
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 joshcough/ffe4ba3794bba74c7a71 to your computer and use it in GitHub Desktop.
Save joshcough/ffe4ba3794bba74c7a71 to your computer and use it in GitHub Desktop.
import Control.Applicative
import Control.Exception
import Control.Monad
import Data.Maybe
import System.IO
withHandle :: Handle -> IO [String]
withHandle h = do
s <- hGetLine h
(s:) <$> (withHandle h)
withHandleT :: Exception e => Handle -> IO [String]
withHandleT h = (either (\_ -> []) id) <$> (try $ do
s <- hGetLine h
(s:) <$> (withHandleT h))
@joshcough
Copy link
Author

[1 of 1] Compiling Main ( Main.hs, interpreted )

Main.hs:12:16:
Could not deduce (Exception e0)
arising from the ambiguity check for ‘withHandleT’
from the context (Exception e)
bound by the type signature for
withHandleT :: Exception e => Handle -> IO [String]
at Main.hs:12:16-51
The type variable ‘e0’ is ambiguous
In the ambiguity check for:
forall e. Exception e => Handle -> IO [String]
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature for ‘withHandleT’:
withHandleT :: Exception e => Handle -> IO [String]
Failed, modules loaded: none.

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