Created
June 25, 2014 01:25
-
-
Save joshcough/ffe4ba3794bba74c7a71 to your computer and use it in GitHub Desktop.
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.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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[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.