Merge pull request #200 from NicolasDP/master

add instance of MonadFailure to CryptoFailable
This commit is contained in:
Vincent Hanquez 2017-11-25 15:25:21 +00:00 committed by GitHub
commit 2293c69f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@
-- Cryptographic Error enumeration and handling -- Cryptographic Error enumeration and handling
-- --
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TypeFamilies #-}
module Crypto.Error.Types module Crypto.Error.Types
( CryptoError(..) ( CryptoError(..)
, CryptoFailable(..) , CryptoFailable(..)
@ -21,6 +22,7 @@ module Crypto.Error.Types
import qualified Control.Exception as E import qualified Control.Exception as E
import Data.Data import Data.Data
import Foundation.Monad (MonadFailure(..))
import Crypto.Internal.Imports import Crypto.Internal.Imports
-- | Enumeration of all possible errors that can be found in this library -- | Enumeration of all possible errors that can be found in this library
@ -87,6 +89,10 @@ instance Monad CryptoFailable where
CryptoPassed a -> m2 a CryptoPassed a -> m2 a
CryptoFailed e -> CryptoFailed e CryptoFailed e -> CryptoFailed e
instance MonadFailure CryptoFailable where
type Failure CryptoFailable = CryptoError
mFail = CryptoFailed
-- | Throw an CryptoError as exception on CryptoFailed result, -- | Throw an CryptoError as exception on CryptoFailed result,
-- otherwise return the computed value -- otherwise return the computed value
throwCryptoErrorIO :: CryptoFailable a -> IO a throwCryptoErrorIO :: CryptoFailable a -> IO a