packages feed

HCL 1.8 → 1.9

raw patch · 5 files changed

+46/−3 lines, 5 filesdep +exceptionsPVP ok

version bump matches the API change (PVP)

Dependencies added: exceptions

API changes (from Hackage documentation)

+ System.Console.HCL: instance Control.Monad.Catch.MonadCatch System.Console.HCL.Request
+ System.Console.HCL: instance Control.Monad.Catch.MonadThrow System.Console.HCL.Request

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # HCL Change Log
 
+## v.1.9
+* Updated to a more recent Haskell Stack snapshot
+* Implemented `MonadThrow` and `MonadCatch` on `Request`
+
 ## v.1.8
 
 * updated to haskell stack
HCL.cabal view
@@ -1,5 +1,5 @@ Name:           HCL-Version:        1.8+Version:        1.9 License:        BSD3 Author:         Justin Bailey Homepage:       http://github.com/m4dc4p/hcl/tree/master@@ -20,7 +20,7 @@  Library   default-language: Haskell2010-  Build-Depends:  base >= 4.9.0.0 && < 5, QuickCheck == 2.*, mtl, random, containers+  Build-Depends:  base >= 4.9.0.0 && < 5, QuickCheck == 2.*, mtl, random, containers, exceptions >= 0.10.7 && < 0.11   Exposed-modules: System.Console.HCL   Hs-Source-Dirs: src @@ -37,12 +37,13 @@   main-is: Spec.hs   hs-source-dirs: test   ghc-options: -threaded -rtsopts -with-rtsopts=-N-  Build-Depends:  base >= 4.7 && < 5, QuickCheck == 2.*, mtl, random, containers, HCL, HUnit+  Build-Depends:  base >= 4.7 && < 5, QuickCheck == 2.*, mtl, random, containers, HCL, HUnit, exceptions >= 0.10.7 && < 0.11   other-modules:     Spec.AndReq     Spec.Constructors     Spec.ReqMaybe     Spec.Monad+    Spec.MonadCatch     Spec.MonadPlus     Spec.NotReq     Spec.OrReq
src/System/Console/HCL.hs view
@@ -311,6 +311,7 @@ import Control.Exception (catch, IOException)
 import Control.Monad (when, MonadPlus)
 import Control.Monad.Trans 
+import qualified Control.Monad.Catch as C
 
 {- |
 The @Request@ data type represents a value requested interactively. The
@@ -409,6 +410,15 @@          -> Request a -- ^ Result of the IO action, as a Request.
 reqIO io = Request $ catch (fmap Just io) $
   \(_ :: IOException) -> return Nothing
+
+-- | Allow throwing exceptions compatible with the exceptions package
+instance C.MonadThrow Request where
+  throwM = Request . C.throwM
+
+-- | Allow catching exceptions compatible with the exceptions package
+instance C.MonadCatch Request where
+  catch happy exceptional =
+    Request $ C.catch (runRequest happy) $ runRequest . exceptional
 
 {- |
 Lifts a @"Maybe" a@ into a @'Request' a@. -}
test/Spec.hs view
@@ -7,6 +7,7 @@ import qualified Spec.AndReq as AndReq
 import qualified Spec.Constructors as Constructors
 import qualified Spec.Monad as Monad
+import qualified Spec.MonadCatch as MonadCatch
 import qualified Spec.MonadPlus as MonadPlus
 import qualified Spec.NotReq as NotReq
 import qualified Spec.OrReq as OrReq
@@ -36,5 +37,6 @@   , ReqLift2.tests
   , ReqAgree.tests
   , Monad.tests
+  , MonadCatch.tests
   , MonadPlus.tests
   ]
+ test/Spec/MonadCatch.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Spec.MonadCatch (tests) where++import Control.Monad.Catch+import Test.HUnit++import System.Console.HCL++tests = TestLabel "Control.Monad.Catch" $ TestList+  [ catchTest+  , noThrowTest+  ]++catchTest = TestLabel "catch" $ TestCase $ do+  val <- runRequest $ catch (throwM TestException >> return False) $+    \(_ :: TestException) -> return True+  assertEqual "" (Just True) val++noThrowTest = TestLabel "catch" $ TestCase $ do+  val <- runRequest $ catch (return False) $+    \(_ :: TestException) -> return True+  assertEqual "" (Just False) val++data TestException = TestException deriving Show+instance Exception TestException