{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module EIO
(
EIO (..)
, runEIO
, throw
, catch
, return
, (>>=)
, (>>)
) where
import Prelude hiding (return, (>>), (>>=))
import Control.Exception (Exception)
import Data.Coerce (coerce)
import Data.Kind (Type)
import qualified GHC.IO as IO
import qualified Prelude
newtype EIO (exceptions :: [Type]) a = EIO
{ forall (exceptions :: [*]) a. EIO exceptions a -> IO a
unEIO :: IO a
} deriving newtype ((forall a b. (a -> b) -> EIO exceptions a -> EIO exceptions b)
-> (forall a b. a -> EIO exceptions b -> EIO exceptions a)
-> Functor (EIO exceptions)
forall (exceptions :: [*]) a b.
a -> EIO exceptions b -> EIO exceptions a
forall (exceptions :: [*]) a b.
(a -> b) -> EIO exceptions a -> EIO exceptions b
forall a b. a -> EIO exceptions b -> EIO exceptions a
forall a b. (a -> b) -> EIO exceptions a -> EIO exceptions b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> EIO exceptions b -> EIO exceptions a
$c<$ :: forall (exceptions :: [*]) a b.
a -> EIO exceptions b -> EIO exceptions a
fmap :: forall a b. (a -> b) -> EIO exceptions a -> EIO exceptions b
$cfmap :: forall (exceptions :: [*]) a b.
(a -> b) -> EIO exceptions a -> EIO exceptions b
Functor)
runEIO :: EIO '[] () -> IO ()
runEIO :: EIO '[] () -> IO ()
runEIO = EIO '[] () -> IO ()
coerce
return :: forall a . a -> EIO '[] a
return :: forall a. a -> EIO '[] a
return = forall a b. Coercible a b => a -> b
coerce @(a -> IO a) a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
Prelude.return
(>>=) :: forall e1 e2 a b . EIO e1 a -> (a -> EIO e2 b) -> EIO (e1 <> e2) b
>>= :: forall (e1 :: [*]) (e2 :: [*]) a b.
EIO e1 a -> (a -> EIO e2 b) -> EIO (e1 <> e2) b
(>>=) = forall a b. Coercible a b => a -> b
coerce @(IO a -> (a -> IO b) -> IO b) IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(Prelude.>>=)
(>>) :: forall e1 e2 a b . EIO e1 a -> EIO e2 b -> EIO (e1 <> e2) b
>> :: forall (e1 :: [*]) (e2 :: [*]) a b.
EIO e1 a -> EIO e2 b -> EIO (e1 <> e2) b
(>>) = forall a b. Coercible a b => a -> b
coerce @(IO a -> IO b -> IO b) IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(Prelude.>>)
type family (<>) (xs :: [Type]) (ys :: [Type]) :: [Type] where
'[] <> ys = ys
xs <> '[] = xs
(x ': xs) <> ys = x ': (xs <> ys)
throw :: forall e a . Exception e => e -> EIO '[ e ] a
throw :: forall e a. Exception e => e -> EIO '[e] a
throw = forall a b. Coercible a b => a -> b
coerce @(e -> IO a) e -> IO a
forall e a. Exception e => e -> IO a
IO.throwIO
catch
:: forall e a e1 e2
. Exception e
=> EIO e1 a
-> (e -> EIO e2 a)
-> EIO (Delete e (e1 <> e2)) a
catch :: forall e a (e1 :: [*]) (e2 :: [*]).
Exception e =>
EIO e1 a -> (e -> EIO e2 a) -> EIO (Delete e (e1 <> e2)) a
catch = forall a b. Coercible a b => a -> b
coerce @(IO a -> (e -> IO a) -> IO a) IO a -> (e -> IO a) -> IO a
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
IO.catch
type family Delete (x :: Type) (xs :: [Type]) :: [Type] where
Delete _ '[] = '[]
Delete x (x ': xs) = Delete x xs
Delete x (y ': xs) = y ': Delete x xs