Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Effects = Union Effects Effects
- type (:&) = Union
- newtype Eff (es :: Effects) a = UnsafeMkEff {
- unsafeUnEff :: IO a
- newtype EffReader r es a = MkEffReader {
- unEffReader :: r -> Eff es a
- effReader :: (r -> Eff es a) -> EffReader r es a
- runEffReader :: r -> EffReader r es a -> Eff es a
- withEffToIO :: e2 :> es => ((forall r. (forall e1. IOE e1 -> Eff (e1 :& es) r) -> IO r) -> IO a) -> IOE e2 -> Eff es a
- hoistReader :: (forall b. m b -> n b) -> ReaderT r m a -> ReaderT r n a
- withMonadIO :: e :> es => IOE e -> (forall m. MonadIO m => m r) -> Eff es r
- withMonadFail :: e :> es => Exception String e -> (forall m. MonadFail m => m r) -> Eff es r
- unsafeRemoveEff :: Eff (e :& es) a -> Eff es a
- runPureEff :: (forall es. Eff es a) -> a
- weakenEff :: (t `In` t') -> Eff t r -> Eff t' r
- insertFirst :: Eff b r -> Eff (c1 :& b) r
- insertSecond :: Eff (c1 :& b) r -> Eff (c1 :& (c2 :& b)) r
- assoc1Eff :: Eff ((a :& b) :& c) r -> Eff (a :& (b :& c)) r
- pushFirst :: Eff a r -> Eff (a :& b) r
- data StateSource (st :: Effects) = StateSource
- newtype Exception e (ex :: Effects) = Exception (forall a. e -> IO a)
- newtype State s (st :: Effects) = UnsafeMkState (IORef s)
- newtype Coroutine a b (s :: Effects) = UnsafeMkCoroutine (a -> IO b)
- type Stream a = Coroutine a ()
- newtype In (a :: Effects) (b :: Effects) = In# (# #)
- eq :: (# #) -> a `In` a
- fstI :: (# #) -> a `In` (a :& b)
- sndI :: (# #) -> a `In` (b :& a)
- cmp :: (a `In` b) -> (b `In` c) -> a `In` c
- bimap :: (a `In` b) -> (c `In` d) -> (a :& c) `In` (b :& d)
- assoc1 :: (# #) -> ((a :& b) :& c) `In` (a :& (b :& c))
- drop :: (a `In` b) -> a `In` (c :& b)
- here :: (a `In` b) -> a `In` (b :& c)
- w :: ((a :& b) `In` c) -> a `In` c
- w2 :: ((b :& a) `In` c) -> a `In` c
- b2 :: (a `In` b) -> (a :& c) `In` (b :& c)
- b :: (a `In` b) -> (c :& a) `In` (c :& b)
- class (es1 :: Effects) :> (es2 :: Effects)
- throw :: ex :> es => Exception e ex -> e -> Eff es a
- has :: forall a b. a :> b => a `In` b
- data Dict c where
- have :: forall a b. (a `In` b) -> Dict (a :> b)
- try :: forall e (es :: Effects) a. (forall ex. Exception e ex -> Eff (ex :& es) a) -> Eff es (Either e a)
- handle :: forall e (es :: Effects) a. (e -> Eff es a) -> (forall ex. Exception e ex -> Eff (ex :& es) a) -> Eff es a
- catch :: forall e (es :: Effects) a. (forall ex. Exception e ex -> Eff (ex :& es) a) -> (e -> Eff es a) -> Eff es a
- get :: st :> es => State s st -> Eff es s
- put :: st :> es => State s st -> s -> Eff es ()
- modify :: st :> es => State s st -> (s -> s) -> Eff es ()
- data MyException where
- MyException :: e -> Unique -> MyException
- withScopedException_ :: ((forall a. e -> IO a) -> IO r) -> IO (Either e r)
- withStateSource :: (forall e. StateSource e -> Eff (e :& es) a) -> Eff es a
- newState :: StateSource e -> s -> Eff es (State s e)
- runState :: s -> (forall st. State s st -> Eff (st :& es) a) -> Eff es (a, s)
- yieldCoroutine :: e1 :> es => Coroutine a b e1 -> a -> Eff es b
- yield :: e1 :> es => Stream a e1 -> a -> Eff es ()
- handleCoroutine :: (a -> Eff es b) -> (z -> Eff es r) -> (forall e1. Coroutine a b e1 -> Eff (e1 :& es) z) -> Eff es r
- forEach :: (forall e1. Coroutine a b e1 -> Eff (e1 :& es) r) -> (a -> Eff es b) -> Eff es r
- inFoldable :: (Foldable t, e1 :> es) => t a -> Stream a e1 -> Eff es ()
- enumerate :: e2 :> es => (forall e1. Stream a e1 -> Eff (e1 :& es) r) -> Stream (Int, a) e2 -> Eff es r
- enumerateFrom :: e2 :> es => Int -> (forall e1. Stream a e1 -> Eff (e1 :& es) r) -> Stream (Int, a) e2 -> Eff es r
- type EarlyReturn = Exception
- withEarlyReturn :: (forall er. EarlyReturn r er -> Eff (er :& es) r) -> Eff es r
- returnEarly :: er :> es => EarlyReturn r er -> r -> Eff es a
- evalState :: s -> (forall st. State s st -> Eff (st :& es) a) -> Eff es a
- withState :: s -> (forall st. State s st -> Eff (st :& es) (s -> a)) -> Eff es a
- data Compound e1 e2 ss where
- compound :: h1 e1 -> h2 e2 -> Compound h1 h2 (e1 :& e2)
- inComp :: forall a b c r. a :> b => b :> c => (a :> c => r) -> r
- withCompound :: forall h1 h2 e es r. e :> es => Compound h1 h2 e -> (forall e1 e2. (e1 :> es, e2 :> es) => h1 e1 -> h2 e2 -> Eff es r) -> Eff es r
- withC1 :: forall e1 e2 ss es r. ss :> es => Compound e1 e2 ss -> (forall st. st :> es => e1 st -> Eff es r) -> Eff es r
- withC2 :: forall e1 e2 ss es r. ss :> es => Compound e1 e2 ss -> (forall st. st :> es => e2 st -> Eff es r) -> Eff es r
- putC :: forall ss es e. ss :> es => Compound e (State Int) ss -> Int -> Eff es ()
- getC :: forall ss es e. ss :> es => Compound e (State Int) ss -> Eff es Int
- runCompound :: e1 s1 -> e2 s2 -> (forall es'. Compound e1 e2 es' -> Eff (es' :& es) r) -> Eff (s1 :& (s2 :& es)) r
- yieldToList :: (forall e1. Stream a e1 -> Eff (e1 :& es) r) -> Eff es ([a], r)
- yieldToReverseList :: (forall e. Stream a e -> Eff (e :& es) r) -> Eff es ([a], r)
- mapStream :: e2 :> es => (a -> b) -> (forall e1. Stream a e1 -> Eff (e1 :& es) r) -> Stream b e2 -> Eff es r
- mapMaybe :: e2 :> es => (a -> Maybe b) -> (forall e1. Stream a e1 -> Eff (e1 :& es) r) -> Stream b e2 -> Eff es r
- catMaybes :: e2 :> es => (forall e1. Stream (Maybe a) e1 -> Eff (e1 :& es) r) -> Stream a e2 -> Eff es r
- type Jump = EarlyReturn ()
- withJump :: (forall j. Jump j -> Eff (j :& es) ()) -> Eff es ()
- jumpTo :: j :> es => Jump j -> Eff es a
- unwrap :: j :> es => Jump j -> Maybe a -> Eff es a
- data IOE (e :: Effects) = MkIOE
- effIO :: e :> es => IOE e -> IO a -> Eff es a
- runEff :: (forall e es. IOE e -> Eff (e :& es) a) -> IO a
- connect :: (forall e1. Coroutine a b e1 -> Eff (e1 :& es) r1) -> (forall e2. a -> Coroutine b a e2 -> Eff (e2 :& es) r2) -> forall e1 e2. (e1 :> es, e2 :> es) => Eff es (Either (r1, a -> Coroutine b a e2 -> Eff es r2) (r2, b -> Coroutine a b e1 -> Eff es r1))
- head' :: forall a b r es. (forall e. Coroutine a b e -> Eff (e :& es) r) -> forall e. e :> es => Eff es (Either r (a, b -> Coroutine a b e -> Eff es r))
- newtype Writer w e = Writer (Stream w e)
- runWriter :: Monoid w => (forall e. Writer w e -> Eff (e :& es) r) -> Eff es (r, w)
- execWriter :: Monoid w => (forall e. Writer w e -> Eff (e :& es) r) -> Eff es w
- tell :: e :> es => Writer w e -> w -> Eff es ()
- newtype Reader r (e :: Effects) = MkReader r
- runReader :: r -> (forall e. Reader r e -> Eff (e :& es) a) -> Eff es a
- ask :: e :> es => Reader r e -> Eff es r
Documentation
newtype Eff (es :: Effects) a Source #
UnsafeMkEff | |
|
newtype EffReader r es a Source #
Because doing IO
operations inside Eff
requires a value-level
argument we can't give IO
-related instances to Eff
directly.
Instead we wrap it in EffReader
.
MkEffReader | |
|
Instances
e :> es => MonadBaseControl IO (EffReader (IOE e) es) Source # | |
e :> es => MonadBase IO (EffReader (IOE e) es) Source # | |
e :> es => MonadFail (EffReader (Exception String e) es) Source # | |
e :> es => MonadIO (EffReader (IOE e) es) Source # | |
Applicative (EffReader r es) Source # | |
Defined in Bluefin.Internal pure :: a -> EffReader r es a # (<*>) :: EffReader r es (a -> b) -> EffReader r es a -> EffReader r es b # liftA2 :: (a -> b -> c) -> EffReader r es a -> EffReader r es b -> EffReader r es c # (*>) :: EffReader r es a -> EffReader r es b -> EffReader r es b # (<*) :: EffReader r es a -> EffReader r es b -> EffReader r es a # | |
Functor (EffReader r es) Source # | |
Monad (EffReader r es) Source # | |
e :> es => MonadUnliftIO (EffReader (IOE e) es) Source # | |
Defined in Bluefin.Internal | |
type StM (EffReader (IOE e) es) a Source # | |
Defined in Bluefin.Internal |
runEffReader :: r -> EffReader r es a -> Eff es a Source #
hoistReader :: (forall b. m b -> n b) -> ReaderT r m a -> ReaderT r n a Source #
runPureEff :: (forall es. Eff es a) -> a Source #
Run an Eff
that doesn't contain any unhandled effects.
data StateSource (st :: Effects) Source #
Handle to a capability to create strict mutable state handles
newtype State s (st :: Effects) Source #
A handle to a strict mutable state of type a
UnsafeMkState (IORef s) |
newtype Coroutine a b (s :: Effects) Source #
A handle to a coroutine that expects values of type a
and then
yields values of type b
.
UnsafeMkCoroutine (a -> IO b) |
type Stream a = Coroutine a () Source #
A handle to a stream that yields values of type a
. It is
implemented as a handle to a coroutine that expects values of type
()
and then yields values of type a
.
class (es1 :: Effects) :> (es2 :: Effects) Source #
Effect subset constraint
Instances
e :> e Source # | A set of effects |
Defined in Bluefin.Internal | |
e :> (e :& es) Source # |
|
Defined in Bluefin.Internal | |
e :> es => e :> (x :& es) Source # | If |
Defined in Bluefin.Internal |
>>> runPureEff $ try $ \e -> do throw e 42 pure "No exception thrown" Left 42
>>> runPureEff $ try $ \e -> do pure "No exception thrown" Right "No exception thrown"
:: forall e (es :: Effects) a. (forall ex. Exception e ex -> Eff (ex :& es) a) | |
-> Eff es (Either e a) |
|
>>> runPureEff $ try $ \e -> do throw e 42 pure "No exception thrown" Left 42
:: forall e (es :: Effects) a. (e -> Eff es a) | If the exception is thrown, apply this handler |
-> (forall ex. Exception e ex -> Eff (ex :& es) a) | |
-> Eff es a |
handle
, but with the argument order swapped
>>> runPureEff $ handle (pure . show) $ \e -> do throw e 42 pure "No exception thrown" "42"
>>> runPureEff $ runState 10 $ \st -> do n <- get st pure (2 * n) (20,10)
:: st :> es | |
=> State s st | |
-> s | The new value of the state. The new value is forced before writing it to the state. |
-> Eff es () |
Set the value of the state
>>> runPureEff $ runState 10 $ \st -> do put st 30 ((), 30)
:: st :> es | |
=> State s st | |
-> (s -> s) | Apply this function to the state. The new value of the state is forced before writing it to the state. |
-> Eff es () |
>>> runPureEff $ runState 10 $ \st -> do modify st (* 2) ((), 20)
data MyException where Source #
MyException :: e -> Unique -> MyException |
Instances
Exception MyException Source # | |
Defined in Bluefin.Internal | |
Show MyException Source # | |
Defined in Bluefin.Internal showsPrec :: Int -> MyException -> ShowS # show :: MyException -> String # showList :: [MyException] -> ShowS # |
:: (forall e. StateSource e -> Eff (e :& es) a) | |
-> Eff es a | ͘ |
:: StateSource e | |
-> s | The initial value for the state handle |
-> Eff es (State s e) | A new state handle |
:: s | Initial state |
-> (forall st. State s st -> Eff (st :& es) a) | Stateful computation |
-> Eff es (a, s) | Result and final state |
>>> runPureEff $ runState 10 $ \st -> do n <- get st pure (2 * n) (20,10)
>>> runPureEff $ yieldToList $ \y -> do yield y 1 yield y 2 yield y 100 ([1,2,100], ())
handleCoroutine :: (a -> Eff es b) -> (z -> Eff es r) -> (forall e1. Coroutine a b e1 -> Eff (e1 :& es) z) -> Eff es r Source #
:: (forall e1. Coroutine a b e1 -> Eff (e1 :& es) r) | |
-> (a -> Eff es b) | Apply this effectful function for each element of the coroutine |
-> Eff es r |
>>> runPureEff $ yieldToList $ \y -> do forEach (inFoldable [0 .. 3]) $ \i -> do yield y i yield y (i * 10) ([0, 0, 1, 10, 2, 20, 3, 30], ())
>>> runPureEff $ yieldToList $ inFoldable [1, 2, 100] ([1, 2, 100], ())
Pair each element in the stream with an increasing index, starting from 0.
>>> runPureEff $ yieldToList $ enumerate (inFoldable ["A", "B", "C"]) ([(0, "A"), (1, "B"), (2, "C")], ())
:: e2 :> es | |
=> Int | Initial value |
-> (forall e1. Stream a e1 -> Eff (e1 :& es) r) | |
-> Stream (Int, a) e2 | |
-> Eff es r |
Pair each element in the stream with an increasing index, starting from an inital value.
>>> runPureEff $ yieldToList $ enumerateFrom1 (inFoldable ["A", "B", "C"]) ([(1, "A"), (2, "B"), (3, "C")], ())
type EarlyReturn = Exception Source #
:: (forall er. EarlyReturn r er -> Eff (er :& es) r) | |
-> Eff es r | ͘ |
Run an Eff
action with the ability to return early to this
point. In the language of exceptions, withEarlyReturn
installs
an exception handler for an exception of type r
.
>>> runPureEff $ withEarlyReturn $ \e -> do for_ [1 .. 10] $ \i -> do when (i >= 5) $ returnEarly e ("Returned early with " ++ show i) pure "End of loop" "Returned early with 5"
:: er :> es | |
=> EarlyReturn r er | |
-> r | Return early to the handler, with this value. |
-> Eff es a |
>>> runPureEff $ withEarlyReturn $ \e -> do for_ [1 .. 10] $ \i -> do when (i >= 5) $ returnEarly e ("Returned early with " ++ show i) pure "End of loop" "Returned early with 5"
:: s | Initial state |
-> (forall st. State s st -> Eff (st :& es) a) | Stateful computation |
-> Eff es a | Result |
>>> runPureEff $ evalState 10 $ \st -> do n <- get st pure (2 * n) 20
:: s | Initial state |
-> (forall st. State s st -> Eff (st :& es) (s -> a)) | Stateful computation |
-> Eff es a | Result |
>>> runPureEff $ withState 10 $ \st -> do n <- get st pure (s -> (2 * n, s)) (20,10)
withC1 :: forall e1 e2 ss es r. ss :> es => Compound e1 e2 ss -> (forall st. st :> es => e1 st -> Eff es r) -> Eff es r Source #
withC2 :: forall e1 e2 ss es r. ss :> es => Compound e1 e2 ss -> (forall st. st :> es => e2 st -> Eff es r) -> Eff es r Source #
>>> runPureEff $ yieldToList $ \y -> do yield y 1 yield y 2 yield y 100 ([1,2,100], ())
:: (forall e. Stream a e -> Eff (e :& es) r) | |
-> Eff es ([a], r) | Yielded elements in reverse order, and final result |
This is more efficient than yieldToList
because it gathers the
elements into a stack in reverse order. yieldToList
then reverses
that stack.
>>> runPureEff $ yieldToReverseList $ \y -> do yield y 1 yield y 2 yield y 100 ([100,2,1], ())
:: e2 :> es | |
=> (forall e1. Stream (Maybe a) e1 -> Eff (e1 :& es) r) | Input stream |
-> Stream a e2 | |
-> Eff es r |
Remove Nothing
elements from a stream.
type Jump = EarlyReturn () Source #
data IOE (e :: Effects) Source #
Handle that allows you to run IO
operations
Instances
e :> es => MonadBaseControl IO (EffReader (IOE e) es) Source # | |
e :> es => MonadBase IO (EffReader (IOE e) es) Source # | |
e :> es => MonadIO (EffReader (IOE e) es) Source # | |
e :> es => MonadUnliftIO (EffReader (IOE e) es) Source # | |
Defined in Bluefin.Internal | |
type StM (EffReader (IOE e) es) a Source # | |
Defined in Bluefin.Internal |
connect :: (forall e1. Coroutine a b e1 -> Eff (e1 :& es) r1) -> (forall e2. a -> Coroutine b a e2 -> Eff (e2 :& es) r2) -> forall e1 e2. (e1 :> es, e2 :> es) => Eff es (Either (r1, a -> Coroutine b a e2 -> Eff es r2) (r2, b -> Coroutine a b e1 -> Eff es r1)) Source #
head' :: forall a b r es. (forall e. Coroutine a b e -> Eff (e :& es) r) -> forall e. e :> es => Eff es (Either r (a, b -> Coroutine a b e -> Eff es r)) Source #