From 393d5804b7ca09a5c7963f215dd038c1c8b9336c Mon Sep 17 00:00:00 2001 From: Nicolas Di Prima Date: Thu, 16 Nov 2017 20:16:29 +0000 Subject: [PATCH] add instance of MonadFailure to CryptoFailable --- Crypto/Error/Types.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Crypto/Error/Types.hs b/Crypto/Error/Types.hs index e2831bf..4b8a977 100644 --- a/Crypto/Error/Types.hs +++ b/Crypto/Error/Types.hs @@ -8,6 +8,7 @@ -- Cryptographic Error enumeration and handling -- {-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE TypeFamilies #-} module Crypto.Error.Types ( CryptoError(..) , CryptoFailable(..) @@ -21,6 +22,7 @@ module Crypto.Error.Types import qualified Control.Exception as E import Data.Data +import Foundation.Monad (MonadFailure(..)) import Crypto.Internal.Imports -- | Enumeration of all possible errors that can be found in this library @@ -87,6 +89,10 @@ instance Monad CryptoFailable where CryptoPassed a -> m2 a CryptoFailed e -> CryptoFailed e +instance MonadFailure CryptoFailable where + type Failure CryptoFailable = CryptoError + mFail = CryptoFailed + -- | Throw an CryptoError as exception on CryptoFailed result, -- otherwise return the computed value throwCryptoErrorIO :: CryptoFailable a -> IO a