{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# OPTIONS_HADDOCK hide #-}
module Streaming.Linear.Internal.Type
(
Stream (..),
Of (..),
)
where
import qualified Control.Functor.Linear as Control
import qualified Data.Functor.Linear as Data
import Prelude.Linear (($), (.))
import qualified Prelude.Linear as Linear
data Stream f m r where
Step :: !(f (Stream f m r)) %1 -> Stream f m r
Effect :: m (Stream f m r) %1 -> Stream f m r
Return :: r %1 -> Stream f m r
data Of a b where
(:>) :: !a -> b %1 -> Of a b
infixr 5 :>
instance (Data.Functor m, Data.Functor f) => Data.Functor (Stream f m) where
fmap ::
(Data.Functor m, Data.Functor f) =>
(a %1 -> b) ->
Stream f m a %1 ->
Stream f m b
fmap :: forall a b.
(Functor m, Functor f) =>
(a %1 -> b) -> Stream f m a %1 -> Stream f m b
fmap a %1 -> b
f Stream f m a
s = forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
(a %1 -> b) -> Stream f m a %1 -> Stream f m b
fmap' a %1 -> b
f Stream f m a
s
{-# INLINEABLE fmap #-}
fmap' ::
(Data.Functor m, Data.Functor f) =>
(a %1 -> b) ->
Stream f m a %1 ->
Stream f m b
fmap' :: forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
(a %1 -> b) -> Stream f m a %1 -> Stream f m b
fmap' a %1 -> b
f (Return a
r) = forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (a %1 -> b
f a
r)
fmap' a %1 -> b
f (Step f (Stream f m a)
fs) = forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.fmap (forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.fmap a %1 -> b
f) f (Stream f m a)
fs
fmap' a %1 -> b
f (Effect m (Stream f m a)
ms) = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.fmap (forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.fmap a %1 -> b
f) m (Stream f m a)
ms
instance
(Control.Functor m, Control.Functor f) =>
Data.Applicative (Stream f m)
where
pure :: a -> Stream f m a
pure :: forall a. a -> Stream f m a
pure = forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return
{-# INLINE pure #-}
(<*>) ::
(Control.Functor m, Control.Functor f) =>
Stream f m (a %1 -> b) %1 ->
Stream f m a %1 ->
Stream f m b
<*> :: forall a b.
(Functor m, Functor f) =>
Stream f m (a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
(<*>) Stream f m (a %1 -> b)
s1 Stream f m a
s2 = forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
Stream f m (a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
app Stream f m (a %1 -> b)
s1 Stream f m a
s2
{-# INLINEABLE (<*>) #-}
app ::
(Control.Functor m, Control.Functor f) =>
Stream f m (a %1 -> b) %1 ->
Stream f m a %1 ->
Stream f m b
app :: forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
Stream f m (a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
app (Return a %1 -> b
f) Stream f m a
stream = forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap a %1 -> b
f Stream f m a
stream
app (Step f (Stream f m (a %1 -> b))
fs) Stream f m a
stream = forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (f :: * -> *) a b.
Applicative f =>
f (a %1 -> b) %1 -> f a %1 -> f b
Data.<*> Stream f m a
stream) f (Stream f m (a %1 -> b))
fs
app (Effect m (Stream f m (a %1 -> b))
ms) Stream f m a
stream = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (f :: * -> *) a b.
Applicative f =>
f (a %1 -> b) %1 -> f a %1 -> f b
Data.<*> Stream f m a
stream) m (Stream f m (a %1 -> b))
ms
instance
(Control.Functor m, Control.Functor f) =>
Control.Functor (Stream f m)
where
fmap ::
(Data.Functor m, Data.Functor f) =>
(a %1 -> b) %1 ->
Stream f m a %1 ->
Stream f m b
fmap :: forall a b.
(Functor m, Functor f) =>
(a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
fmap a %1 -> b
f Stream f m a
s = forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
(a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
fmap'' a %1 -> b
f Stream f m a
s
{-# INLINEABLE fmap #-}
fmap'' ::
(Control.Functor m, Control.Functor f) =>
(a %1 -> b) %1 ->
Stream f m a %1 ->
Stream f m b
fmap'' :: forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
(a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
fmap'' a %1 -> b
f (Return a
r) = forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (a %1 -> b
f a
r)
fmap'' a %1 -> b
f (Step f (Stream f m a)
fs) = forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap a %1 -> b
f) f (Stream f m a)
fs
fmap'' a %1 -> b
f (Effect m (Stream f m a)
ms) = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap a %1 -> b
f) m (Stream f m a)
ms
instance
(Control.Functor m, Control.Functor f) =>
Control.Applicative (Stream f m)
where
pure :: a %1 -> Stream f m a
pure :: forall a. a %1 -> Stream f m a
pure = forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return
{-# INLINE pure #-}
(<*>) ::
(Control.Functor m, Control.Functor f) =>
Stream f m (a %1 -> b) %1 ->
Stream f m a %1 ->
Stream f m b
<*> :: forall a b.
(Functor m, Functor f) =>
Stream f m (a %1 -> b) %1 -> Stream f m a %1 -> Stream f m b
(<*>) = forall (f :: * -> *) a b.
Applicative f =>
f (a %1 -> b) %1 -> f a %1 -> f b
(Data.<*>)
{-# INLINE (<*>) #-}
instance
(Control.Functor m, Control.Functor f) =>
Control.Monad (Stream f m)
where
(>>=) :: Stream f m a %1 -> (a %1 -> Stream f m b) %1 -> Stream f m b
>>= :: forall a b.
Stream f m a %1 -> (a %1 -> Stream f m b) %1 -> Stream f m b
(>>=) = forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
Stream f m a %1 -> (a %1 -> Stream f m b) %1 -> Stream f m b
bind
{-# INLINEABLE (>>=) #-}
bind ::
(Control.Functor m, Control.Functor f) =>
Stream f m a %1 ->
(a %1 -> Stream f m b) %1 ->
Stream f m b
bind :: forall (m :: * -> *) (f :: * -> *) a b.
(Functor m, Functor f) =>
Stream f m a %1 -> (a %1 -> Stream f m b) %1 -> Stream f m b
bind (Return a
a) a %1 -> Stream f m b
f = a %1 -> Stream f m b
f a
a
bind (Step f (Stream f m a)
fs) a %1 -> Stream f m b
f = forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= a %1 -> Stream f m b
f) f (Stream f m a)
fs
bind (Effect m (Stream f m a)
ms) a %1 -> Stream f m b
f = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= a %1 -> Stream f m b
f) m (Stream f m a)
ms
instance (Control.Functor f) => Control.MonadTrans (Stream f) where
lift :: (Control.Functor m, Control.Functor f) => m a %1 -> Stream f m a
lift :: forall (m :: * -> *) a.
(Functor m, Functor f) =>
m a %1 -> Stream f m a
lift = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return
{-# INLINE lift #-}
ofFmap :: (a %1 -> b) %1 -> (Of x a) %1 -> (Of x b)
ofFmap :: forall a b x. (a %1 -> b) %1 -> Of x a %1 -> Of x b
ofFmap a %1 -> b
f (x
a :> a
b) = x
a forall a b. a -> b -> Of a b
:> a %1 -> b
f a
b
{-# INLINE ofFmap #-}
instance Data.Functor (Of a) where
fmap :: forall a b. (a %1 -> b) -> Of a a %1 -> Of a b
fmap = forall a b. (a %1 -> b) %1 -> a -> b
Linear.forget forall a b x. (a %1 -> b) %1 -> Of x a %1 -> Of x b
ofFmap
{-# INLINE fmap #-}
instance Control.Functor (Of a) where
fmap :: forall a b. (a %1 -> b) %1 -> Of a a %1 -> Of a b
fmap = forall a b x. (a %1 -> b) %1 -> Of x a %1 -> Of x b
ofFmap
{-# INLINE fmap #-}