{-# LANGUAGE FlexibleInstances #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Database.PostgreSQL.Pure.Internal.MonadFail
  ( fromEither
  ) where

import           Prelude            (Either (Left, Right), String, pure)

import           Control.Monad.Fail (MonadFail (fail))

instance MonadFail (Either String) where
  fail :: String -> Either String a
fail = String -> Either String a
forall a b. a -> Either a b
Left

fromEither :: MonadFail m => Either String a -> m a
fromEither :: Either String a -> m a
fromEither (Right a
a) = a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
fromEither (Left String
e)  = String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
e