{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_HADDOCK not-home #-}
module Data.Conduino.Internal (
Pipe(..)
, PipeF(..)
, awaitEither
, yield
, trimapPipe, mapInput, mapOutput, mapUpRes
, hoistPipe
, RecPipe
, toRecPipe, fromRecPipe
, withRecPipe
, runStateP
, pAwaitF, pYieldF
) where
import Control.Applicative
import Control.Monad.Catch
import Control.Monad.Except
import Control.Monad.Free.Class
import Control.Monad.Free.TH
import Control.Monad.RWS
import Control.Monad.Trans.Free (FreeT(..), FreeF(..))
import Control.Monad.Trans.Free.Church
import Control.Monad.Trans.State
import Data.Functor
#if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail
#endif
data PipeF i o u a =
PAwaitF (u -> a) (i -> a)
| PYieldF o a
deriving a -> PipeF i o u b -> PipeF i o u a
(a -> b) -> PipeF i o u a -> PipeF i o u b
(forall a b. (a -> b) -> PipeF i o u a -> PipeF i o u b)
-> (forall a b. a -> PipeF i o u b -> PipeF i o u a)
-> Functor (PipeF i o u)
forall a b. a -> PipeF i o u b -> PipeF i o u a
forall a b. (a -> b) -> PipeF i o u a -> PipeF i o u b
forall i o u a b. a -> PipeF i o u b -> PipeF i o u a
forall i o u a b. (a -> b) -> PipeF i o u a -> PipeF i o u b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PipeF i o u b -> PipeF i o u a
$c<$ :: forall i o u a b. a -> PipeF i o u b -> PipeF i o u a
fmap :: (a -> b) -> PipeF i o u a -> PipeF i o u b
$cfmap :: forall i o u a b. (a -> b) -> PipeF i o u a -> PipeF i o u b
Functor
makeFree ''PipeF
newtype Pipe i o u m a = Pipe { Pipe i o u m a -> FT (PipeF i o u) m a
pipeFree :: FT (PipeF i o u) m a }
deriving
( a -> Pipe i o u m b -> Pipe i o u m a
(a -> b) -> Pipe i o u m a -> Pipe i o u m b
(forall a b. (a -> b) -> Pipe i o u m a -> Pipe i o u m b)
-> (forall a b. a -> Pipe i o u m b -> Pipe i o u m a)
-> Functor (Pipe i o u m)
forall a b. a -> Pipe i o u m b -> Pipe i o u m a
forall a b. (a -> b) -> Pipe i o u m a -> Pipe i o u m b
forall i o u (m :: * -> *) a b.
a -> Pipe i o u m b -> Pipe i o u m a
forall i o u (m :: * -> *) a b.
(a -> b) -> Pipe i o u m a -> Pipe i o u m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Pipe i o u m b -> Pipe i o u m a
$c<$ :: forall i o u (m :: * -> *) a b.
a -> Pipe i o u m b -> Pipe i o u m a
fmap :: (a -> b) -> Pipe i o u m a -> Pipe i o u m b
$cfmap :: forall i o u (m :: * -> *) a b.
(a -> b) -> Pipe i o u m a -> Pipe i o u m b
Functor
, Functor (Pipe i o u m)
a -> Pipe i o u m a
Functor (Pipe i o u m) =>
(forall a. a -> Pipe i o u m a)
-> (forall a b.
Pipe i o u m (a -> b) -> Pipe i o u m a -> Pipe i o u m b)
-> (forall a b c.
(a -> b -> c)
-> Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m c)
-> (forall a b. Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b)
-> (forall a b. Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m a)
-> Applicative (Pipe i o u m)
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m a
Pipe i o u m (a -> b) -> Pipe i o u m a -> Pipe i o u m b
(a -> b -> c) -> Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m c
forall a. a -> Pipe i o u m a
forall a b. Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m a
forall a b. Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
forall a b.
Pipe i o u m (a -> b) -> Pipe i o u m a -> Pipe i o u m b
forall a b c.
(a -> b -> c) -> Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m c
forall i o u (m :: * -> *). Functor (Pipe i o u m)
forall i o u (m :: * -> *) a. a -> Pipe i o u m a
forall i o u (m :: * -> *) a b.
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m a
forall i o u (m :: * -> *) a b.
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
forall i o u (m :: * -> *) a b.
Pipe i o u m (a -> b) -> Pipe i o u m a -> Pipe i o u m b
forall i o u (m :: * -> *) a b c.
(a -> b -> c) -> Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m a
$c<* :: forall i o u (m :: * -> *) a b.
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m a
*> :: Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
$c*> :: forall i o u (m :: * -> *) a b.
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
liftA2 :: (a -> b -> c) -> Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m c
$cliftA2 :: forall i o u (m :: * -> *) a b c.
(a -> b -> c) -> Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m c
<*> :: Pipe i o u m (a -> b) -> Pipe i o u m a -> Pipe i o u m b
$c<*> :: forall i o u (m :: * -> *) a b.
Pipe i o u m (a -> b) -> Pipe i o u m a -> Pipe i o u m b
pure :: a -> Pipe i o u m a
$cpure :: forall i o u (m :: * -> *) a. a -> Pipe i o u m a
$cp1Applicative :: forall i o u (m :: * -> *). Functor (Pipe i o u m)
Applicative
, Applicative (Pipe i o u m)
a -> Pipe i o u m a
Applicative (Pipe i o u m) =>
(forall a b.
Pipe i o u m a -> (a -> Pipe i o u m b) -> Pipe i o u m b)
-> (forall a b. Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b)
-> (forall a. a -> Pipe i o u m a)
-> Monad (Pipe i o u m)
Pipe i o u m a -> (a -> Pipe i o u m b) -> Pipe i o u m b
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
forall a. a -> Pipe i o u m a
forall a b. Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
forall a b.
Pipe i o u m a -> (a -> Pipe i o u m b) -> Pipe i o u m b
forall i o u (m :: * -> *). Applicative (Pipe i o u m)
forall i o u (m :: * -> *) a. a -> Pipe i o u m a
forall i o u (m :: * -> *) a b.
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
forall i o u (m :: * -> *) a b.
Pipe i o u m a -> (a -> Pipe i o u m b) -> Pipe i o u m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> Pipe i o u m a
$creturn :: forall i o u (m :: * -> *) a. a -> Pipe i o u m a
>> :: Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
$c>> :: forall i o u (m :: * -> *) a b.
Pipe i o u m a -> Pipe i o u m b -> Pipe i o u m b
>>= :: Pipe i o u m a -> (a -> Pipe i o u m b) -> Pipe i o u m b
$c>>= :: forall i o u (m :: * -> *) a b.
Pipe i o u m a -> (a -> Pipe i o u m b) -> Pipe i o u m b
$cp1Monad :: forall i o u (m :: * -> *). Applicative (Pipe i o u m)
Monad
, m a -> Pipe i o u m a
(forall (m :: * -> *) a. Monad m => m a -> Pipe i o u m a)
-> MonadTrans (Pipe i o u)
forall i o u (m :: * -> *) a. Monad m => m a -> Pipe i o u m a
forall (m :: * -> *) a. Monad m => m a -> Pipe i o u m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> Pipe i o u m a
$clift :: forall i o u (m :: * -> *) a. Monad m => m a -> Pipe i o u m a
MonadTrans
, MonadFree (PipeF i o u)
, Monad (Pipe i o u m)
Monad (Pipe i o u m) =>
(forall a. IO a -> Pipe i o u m a) -> MonadIO (Pipe i o u m)
IO a -> Pipe i o u m a
forall a. IO a -> Pipe i o u m a
forall i o u (m :: * -> *). MonadIO m => Monad (Pipe i o u m)
forall i o u (m :: * -> *) a. MonadIO m => IO a -> Pipe i o u m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> Pipe i o u m a
$cliftIO :: forall i o u (m :: * -> *) a. MonadIO m => IO a -> Pipe i o u m a
$cp1MonadIO :: forall i o u (m :: * -> *). MonadIO m => Monad (Pipe i o u m)
MonadIO
, MonadState s
, MonadReader r
, MonadWriter w
, MonadError e
, MonadRWS r w s
, Applicative (Pipe i o u m)
Pipe i o u m a
Applicative (Pipe i o u m) =>
(forall a. Pipe i o u m a)
-> (forall a. Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a)
-> (forall a. Pipe i o u m a -> Pipe i o u m [a])
-> (forall a. Pipe i o u m a -> Pipe i o u m [a])
-> Alternative (Pipe i o u m)
Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
Pipe i o u m a -> Pipe i o u m [a]
Pipe i o u m a -> Pipe i o u m [a]
forall a. Pipe i o u m a
forall a. Pipe i o u m a -> Pipe i o u m [a]
forall a. Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
forall i o u (m :: * -> *).
Alternative m =>
Applicative (Pipe i o u m)
forall i o u (m :: * -> *) a. Alternative m => Pipe i o u m a
forall i o u (m :: * -> *) a.
Alternative m =>
Pipe i o u m a -> Pipe i o u m [a]
forall i o u (m :: * -> *) a.
Alternative m =>
Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: Pipe i o u m a -> Pipe i o u m [a]
$cmany :: forall i o u (m :: * -> *) a.
Alternative m =>
Pipe i o u m a -> Pipe i o u m [a]
some :: Pipe i o u m a -> Pipe i o u m [a]
$csome :: forall i o u (m :: * -> *) a.
Alternative m =>
Pipe i o u m a -> Pipe i o u m [a]
<|> :: Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
$c<|> :: forall i o u (m :: * -> *) a.
Alternative m =>
Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
empty :: Pipe i o u m a
$cempty :: forall i o u (m :: * -> *) a. Alternative m => Pipe i o u m a
$cp1Alternative :: forall i o u (m :: * -> *).
Alternative m =>
Applicative (Pipe i o u m)
Alternative
, Monad (Pipe i o u m)
Alternative (Pipe i o u m)
Pipe i o u m a
(Alternative (Pipe i o u m), Monad (Pipe i o u m)) =>
(forall a. Pipe i o u m a)
-> (forall a. Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a)
-> MonadPlus (Pipe i o u m)
Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
forall a. Pipe i o u m a
forall a. Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
forall i o u (m :: * -> *). MonadPlus m => Monad (Pipe i o u m)
forall i o u (m :: * -> *).
MonadPlus m =>
Alternative (Pipe i o u m)
forall i o u (m :: * -> *) a. MonadPlus m => Pipe i o u m a
forall i o u (m :: * -> *) a.
MonadPlus m =>
Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
mplus :: Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
$cmplus :: forall i o u (m :: * -> *) a.
MonadPlus m =>
Pipe i o u m a -> Pipe i o u m a -> Pipe i o u m a
mzero :: Pipe i o u m a
$cmzero :: forall i o u (m :: * -> *) a. MonadPlus m => Pipe i o u m a
$cp2MonadPlus :: forall i o u (m :: * -> *). MonadPlus m => Monad (Pipe i o u m)
$cp1MonadPlus :: forall i o u (m :: * -> *).
MonadPlus m =>
Alternative (Pipe i o u m)
MonadPlus
, Monad (Pipe i o u m)
e -> Pipe i o u m a
Monad (Pipe i o u m) =>
(forall e a. Exception e => e -> Pipe i o u m a)
-> MonadThrow (Pipe i o u m)
forall e a. Exception e => e -> Pipe i o u m a
forall i o u (m :: * -> *). MonadThrow m => Monad (Pipe i o u m)
forall i o u (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> Pipe i o u m a
forall (m :: * -> *).
Monad m =>
(forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: e -> Pipe i o u m a
$cthrowM :: forall i o u (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> Pipe i o u m a
$cp1MonadThrow :: forall i o u (m :: * -> *). MonadThrow m => Monad (Pipe i o u m)
MonadThrow
, MonadThrow (Pipe i o u m)
MonadThrow (Pipe i o u m) =>
(forall e a.
Exception e =>
Pipe i o u m a -> (e -> Pipe i o u m a) -> Pipe i o u m a)
-> MonadCatch (Pipe i o u m)
Pipe i o u m a -> (e -> Pipe i o u m a) -> Pipe i o u m a
forall e a.
Exception e =>
Pipe i o u m a -> (e -> Pipe i o u m a) -> Pipe i o u m a
forall i o u (m :: * -> *).
MonadCatch m =>
MonadThrow (Pipe i o u m)
forall i o u (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
Pipe i o u m a -> (e -> Pipe i o u m a) -> Pipe i o u m a
forall (m :: * -> *).
MonadThrow m =>
(forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: Pipe i o u m a -> (e -> Pipe i o u m a) -> Pipe i o u m a
$ccatch :: forall i o u (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
Pipe i o u m a -> (e -> Pipe i o u m a) -> Pipe i o u m a
$cp1MonadCatch :: forall i o u (m :: * -> *).
MonadCatch m =>
MonadThrow (Pipe i o u m)
MonadCatch
)
instance MonadFail m => MonadFail (Pipe i o u m) where
#if MIN_VERSION_base(4,13,0)
fail :: String -> Pipe i o u m a
fail = m a -> Pipe i o u m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> Pipe i o u m a)
-> (String -> m a) -> String -> Pipe i o u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail
#else
fail = lift . Control.Monad.Fail.fail
#endif
awaitEither :: Pipe i o u m (Either u i)
awaitEither :: Pipe i o u m (Either u i)
awaitEither = Pipe i o u m (Either u i)
forall (m :: * -> *) i o u.
MonadFree (PipeF i o u) m =>
m (Either u i)
pAwaitF
yield :: o -> Pipe i o u m ()
yield :: o -> Pipe i o u m ()
yield = o -> Pipe i o u m ()
forall (m :: * -> *) i o u. MonadFree (PipeF i o u) m => o -> m ()
pYieldF
trimapPipe
:: (i -> j)
-> (p -> o)
-> (u -> v)
-> Pipe j p v m a
-> Pipe i o u m a
trimapPipe :: (i -> j)
-> (p -> o) -> (u -> v) -> Pipe j p v m a -> Pipe i o u m a
trimapPipe f :: i -> j
f g :: p -> o
g h :: u -> v
h = FT (PipeF i o u) m a -> Pipe i o u m a
forall i o u (m :: * -> *) a.
FT (PipeF i o u) m a -> Pipe i o u m a
Pipe (FT (PipeF i o u) m a -> Pipe i o u m a)
-> (Pipe j p v m a -> FT (PipeF i o u) m a)
-> Pipe j p v m a
-> Pipe i o u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. PipeF j p v a -> PipeF i o u a)
-> FT (PipeF j p v) m a -> FT (PipeF i o u) m a
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) b.
(forall a. f a -> g a) -> FT f m b -> FT g m b
transFT forall a. PipeF j p v a -> PipeF i o u a
go (FT (PipeF j p v) m a -> FT (PipeF i o u) m a)
-> (Pipe j p v m a -> FT (PipeF j p v) m a)
-> Pipe j p v m a
-> FT (PipeF i o u) m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe j p v m a -> FT (PipeF j p v) m a
forall i o u (m :: * -> *) a.
Pipe i o u m a -> FT (PipeF i o u) m a
pipeFree
where
go :: PipeF j p v a -> PipeF i o u a
go = \case
PAwaitF a :: v -> a
a b :: j -> a
b -> (u -> a) -> (i -> a) -> PipeF i o u a
forall i o u a. (u -> a) -> (i -> a) -> PipeF i o u a
PAwaitF (v -> a
a (v -> a) -> (u -> v) -> u -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. u -> v
h) (j -> a
b (j -> a) -> (i -> j) -> i -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> j
f)
PYieldF a :: p
a x :: a
x -> o -> a -> PipeF i o u a
forall i o u a. o -> a -> PipeF i o u a
PYieldF (p -> o
g p
a) a
x
hoistPipe
:: (Monad m, Monad n)
=> (forall x. m x -> n x)
-> Pipe i o u m a
-> Pipe i o u n a
hoistPipe :: (forall x. m x -> n x) -> Pipe i o u m a -> Pipe i o u n a
hoistPipe f :: forall x. m x -> n x
f = FT (PipeF i o u) n a -> Pipe i o u n a
forall i o u (m :: * -> *) a.
FT (PipeF i o u) m a -> Pipe i o u m a
Pipe (FT (PipeF i o u) n a -> Pipe i o u n a)
-> (Pipe i o u m a -> FT (PipeF i o u) n a)
-> Pipe i o u m a
-> Pipe i o u n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall x. m x -> n x)
-> FT (PipeF i o u) m a -> FT (PipeF i o u) n a
forall (m :: * -> *) (n :: * -> *) (f :: * -> *) b.
(Monad m, Monad n) =>
(forall a. m a -> n a) -> FT f m b -> FT f n b
hoistFT forall x. m x -> n x
f (FT (PipeF i o u) m a -> FT (PipeF i o u) n a)
-> (Pipe i o u m a -> FT (PipeF i o u) m a)
-> Pipe i o u m a
-> FT (PipeF i o u) n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i o u m a -> FT (PipeF i o u) m a
forall i o u (m :: * -> *) a.
Pipe i o u m a -> FT (PipeF i o u) m a
pipeFree
mapInput :: (i -> j) -> Pipe j o u m a -> Pipe i o u m a
mapInput :: (i -> j) -> Pipe j o u m a -> Pipe i o u m a
mapInput f :: i -> j
f = (i -> j)
-> (o -> o) -> (u -> u) -> Pipe j o u m a -> Pipe i o u m a
forall i j p o u v (m :: * -> *) a.
(i -> j)
-> (p -> o) -> (u -> v) -> Pipe j p v m a -> Pipe i o u m a
trimapPipe i -> j
f o -> o
forall a. a -> a
id u -> u
forall a. a -> a
id
mapOutput :: (p -> o) -> Pipe i p u m a -> Pipe i o u m a
mapOutput :: (p -> o) -> Pipe i p u m a -> Pipe i o u m a
mapOutput f :: p -> o
f = (i -> i)
-> (p -> o) -> (u -> u) -> Pipe i p u m a -> Pipe i o u m a
forall i j p o u v (m :: * -> *) a.
(i -> j)
-> (p -> o) -> (u -> v) -> Pipe j p v m a -> Pipe i o u m a
trimapPipe i -> i
forall a. a -> a
id p -> o
f u -> u
forall a. a -> a
id
mapUpRes :: (u -> v) -> Pipe i o v m a -> Pipe i o u m a
mapUpRes :: (u -> v) -> Pipe i o v m a -> Pipe i o u m a
mapUpRes = (i -> i)
-> (o -> o) -> (u -> v) -> Pipe i o v m a -> Pipe i o u m a
forall i j p o u v (m :: * -> *) a.
(i -> j)
-> (p -> o) -> (u -> v) -> Pipe j p v m a -> Pipe i o u m a
trimapPipe i -> i
forall a. a -> a
id o -> o
forall a. a -> a
id
type RecPipe i o u = FreeT (PipeF i o u)
toRecPipe :: Monad m => Pipe i o u m a -> RecPipe i o u m a
toRecPipe :: Pipe i o u m a -> RecPipe i o u m a
toRecPipe = FT (PipeF i o u) m a -> RecPipe i o u m a
forall (m :: * -> *) (f :: * -> *) a.
(Monad m, Functor f) =>
FT f m a -> FreeT f m a
fromFT (FT (PipeF i o u) m a -> RecPipe i o u m a)
-> (Pipe i o u m a -> FT (PipeF i o u) m a)
-> Pipe i o u m a
-> RecPipe i o u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i o u m a -> FT (PipeF i o u) m a
forall i o u (m :: * -> *) a.
Pipe i o u m a -> FT (PipeF i o u) m a
pipeFree
fromRecPipe :: Monad m => RecPipe i o u m a -> Pipe i o u m a
fromRecPipe :: RecPipe i o u m a -> Pipe i o u m a
fromRecPipe = FT (PipeF i o u) m a -> Pipe i o u m a
forall i o u (m :: * -> *) a.
FT (PipeF i o u) m a -> Pipe i o u m a
Pipe (FT (PipeF i o u) m a -> Pipe i o u m a)
-> (RecPipe i o u m a -> FT (PipeF i o u) m a)
-> RecPipe i o u m a
-> Pipe i o u m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecPipe i o u m a -> FT (PipeF i o u) m a
forall (m :: * -> *) (f :: * -> *) a.
Monad m =>
FreeT f m a -> FT f m a
toFT
withRecPipe
:: (Monad m, Monad n)
=> (RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a
-> Pipe j p v n b
withRecPipe :: (RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe f :: RecPipe i o u m a -> RecPipe j p v n b
f = RecPipe j p v n b -> Pipe j p v n b
forall (m :: * -> *) i o u a.
Monad m =>
RecPipe i o u m a -> Pipe i o u m a
fromRecPipe (RecPipe j p v n b -> Pipe j p v n b)
-> (Pipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a
-> Pipe j p v n b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecPipe i o u m a -> RecPipe j p v n b
f (RecPipe i o u m a -> RecPipe j p v n b)
-> (Pipe i o u m a -> RecPipe i o u m a)
-> Pipe i o u m a
-> RecPipe j p v n b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i o u m a -> RecPipe i o u m a
forall (m :: * -> *) i o u a.
Monad m =>
Pipe i o u m a -> RecPipe i o u m a
toRecPipe
runStateP
:: Monad m
=> s
-> Pipe i o u (StateT s m) a
-> Pipe i o u m (a, s)
runStateP :: s -> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
runStateP = (RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s))
-> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s)
forall (m :: * -> *) (n :: * -> *) i o u a j p v b.
(Monad m, Monad n) =>
(RecPipe i o u m a -> RecPipe j p v n b)
-> Pipe i o u m a -> Pipe j p v n b
withRecPipe ((RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s))
-> Pipe i o u (StateT s m) a -> Pipe i o u m (a, s))
-> (s -> RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s))
-> s
-> Pipe i o u (StateT s m) a
-> Pipe i o u m (a, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> RecPipe i o u (StateT s m) a -> RecPipe i o u m (a, s)
forall (m :: * -> *) (f :: * -> *) t a.
(Functor m, Functor f) =>
t -> FreeT f (StateT t m) a -> FreeT f m (a, t)
go
where
go :: t -> FreeT f (StateT t m) a -> FreeT f m (a, t)
go s :: t
s (FreeT p :: StateT t m (FreeF f a (FreeT f (StateT t m) a))
p) = m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t))
-> m (FreeF f (a, t) (FreeT f m (a, t))) -> FreeT f m (a, t)
forall a b. (a -> b) -> a -> b
$ StateT t m (FreeF f a (FreeT f (StateT t m) a))
-> t -> m (FreeF f a (FreeT f (StateT t m) a), t)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT StateT t m (FreeF f a (FreeT f (StateT t m) a))
p t
s m (FreeF f a (FreeT f (StateT t m) a), t)
-> ((FreeF f a (FreeT f (StateT t m) a), t)
-> FreeF f (a, t) (FreeT f m (a, t)))
-> m (FreeF f (a, t) (FreeT f m (a, t)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(q :: FreeF f a (FreeT f (StateT t m) a)
q, s' :: t
s') ->
case FreeF f a (FreeT f (StateT t m) a)
q of
Pure x :: a
x -> (a, t) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. a -> FreeF f a b
Pure (a
x, t
s')
Free l :: f (FreeT f (StateT t m) a)
l -> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall (f :: * -> *) a b. f b -> FreeF f a b
Free (f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t)))
-> f (FreeT f m (a, t)) -> FreeF f (a, t) (FreeT f m (a, t))
forall a b. (a -> b) -> a -> b
$ t -> FreeT f (StateT t m) a -> FreeT f m (a, t)
go t
s' (FreeT f (StateT t m) a -> FreeT f m (a, t))
-> f (FreeT f (StateT t m) a) -> f (FreeT f m (a, t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (FreeT f (StateT t m) a)
l