Skip to content

Commit ff92ae6

Browse files
committed
Avoid use of catch to fix compilation on old GHC
1 parent e8f874a commit ff92ae6

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/NumberSix.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Control.Monad (forM, forM_)
1515
import Data.Maybe (catMaybes)
1616
import qualified Data.Text as T
1717
import qualified Database.SQLite.Simple as Sqlite
18-
import Prelude hiding (catch)
1918
import System.Environment (getProgName)
2019

2120

src/NumberSix/Handlers/Http.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ module NumberSix.Handlers.Http
66

77

88
--------------------------------------------------------------------------------
9-
import Control.Exception (SomeException (..), catch)
9+
import Control.Exception (SomeException (..), handle)
1010
import Control.Monad.Trans (liftIO)
1111
import Data.Text (Text)
1212
import qualified Data.Text as T
1313
import qualified Data.Text.Encoding as T
1414
import qualified Network.HTTP.Conduit as H
1515
import qualified Network.HTTP.Types as H
16-
import Prelude hiding (catch)
1716

1817

1918
--------------------------------------------------------------------------------
@@ -48,8 +47,9 @@ http uri = do
4847
--------------------------------------------------------------------------------
4948
-- | Catch possible network errors
5049
wrapped :: Text -> IO Text
51-
wrapped uri = catch (http uri) $ \(SomeException e) ->
52-
return $ T.pack $ show e
50+
wrapped uri = handle
51+
(\(SomeException e) -> return $ T.pack $ show e)
52+
(http uri)
5353

5454

5555
--------------------------------------------------------------------------------

src/NumberSix/Handlers/NowPlaying.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ module NumberSix.Handlers.NowPlaying
77

88
--------------------------------------------------------------------------------
99
import Control.Applicative ((<$>))
10-
import Control.Exception
10+
import Control.Exception (SomeException (..), handle)
1111
import Control.Monad.Trans (liftIO)
1212
import Data.Text (Text)
1313
import qualified Data.Text.Encoding as T
1414
import qualified Network.HTTP.Conduit as HC
15-
import Prelude hiding (catch)
1615
import Text.XmlHtml
1716
import Text.XmlHtml.Cursor
1817

@@ -62,8 +61,8 @@ rgrfm = do
6261

6362
--------------------------------------------------------------------------------
6463
urgent :: IO Text
65-
urgent = catch
66-
(T.decodeUtf8 <$> http url id) (\(SomeException _) -> randomError)
64+
urgent = handle
65+
(\(SomeException _) -> randomError) (T.decodeUtf8 <$> http url id)
6766
where
6867
url = "http://urgent.fm/nowplaying/livetrack.txt"
6968

src/NumberSix/Handlers/Resto.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ resto arg = do
6363
url = "http://zeus.ugent.be/hydra/api/1.0/resto/week/" ++
6464
dropWhile (== '0') week ++ ".json"
6565

66+
print url
6667
http (T.pack url) id >>= \bs -> case parseJsonEither bs of
6768
Left _ -> randomError
6869
Right (WeekMenu m) -> return $ case M.lookup (T.pack day) m of

src/NumberSix/Handlers/Weather.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module NumberSix.Handlers.Weather
1010

1111
--------------------------------------------------------------------------------
1212
import Control.Applicative ((<$>), (<*>))
13-
import Control.Exception (catch)
13+
import Control.Exception (handle)
1414
import Control.Monad (mzero)
1515
import Control.Monad.Trans (liftIO)
1616
import Data.Aeson (FromJSON (..), Value (..), (.:))
@@ -77,8 +77,9 @@ instance Show Description where
7777
--------------------------------------------------------------------------------
7878
getWeather :: Text -> IO (Maybe Weather)
7979
getWeather query = do
80-
result <- ((parseJsonEither <$> http url id) :: IO (Either String Weather))
81-
`catch` (\ex -> return $ Left $ show (ex :: HttpException))
80+
result <- handle
81+
(\ex -> return $ Left $ show (ex :: HttpException))
82+
((parseJsonEither <$> http url id) :: IO (Either String Weather))
8283
either (const $ return Nothing) (return . Just) result
8384
where
8485
loc = if T.null query then "gent" else query

0 commit comments

Comments
 (0)