{-# LANGUAGE FlexibleInstances #-}
module Zwirn.Core.Cord where
import Control.Monad (join)
import Data.Bifunctor (first, second)
import Zwirn.Core.Core
import Zwirn.Core.Query
import Zwirn.Core.Random
import Zwirn.Core.Time
import Zwirn.Core.Tree
import Zwirn.Core.Types
type Cord = ZwirnT Tree
liftList :: ([Tree (Value i a, st)] -> [Tree (Value i b, st)]) -> Cord st i a -> Cord st i b
liftList :: forall i a st b.
([Tree (Value i a, st)] -> [Tree (Value i b, st)])
-> Cord st i a -> Cord st i b
liftList [Tree (Value i a, st)] -> [Tree (Value i b, st)]
f = (Tree (Value i a, st) -> Tree (Value i b, st))
-> ZwirnT Tree st i a -> ZwirnT Tree st i b
forall (k :: * -> *) i a st b.
(k (Value i a, st) -> k (Value i b, st))
-> ZwirnT k st i a -> ZwirnT k st i b
withInner Tree (Value i a, st) -> Tree (Value i b, st)
g
where
g :: Tree (Value i a, st) -> Tree (Value i b, st)
g (Leaf (Value i a, st)
x) = [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a. [Tree a] -> Tree a
Branch ([Tree (Value i b, st)] -> Tree (Value i b, st))
-> [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a b. (a -> b) -> a -> b
$ [Tree (Value i a, st)] -> [Tree (Value i b, st)]
f [(Value i a, st) -> Tree (Value i a, st)
forall a. a -> Tree a
Leaf (Value i a, st)
x]
g (Branch [Tree (Value i a, st)]
xs) = [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a. [Tree a] -> Tree a
Branch ([Tree (Value i b, st)] -> Tree (Value i b, st))
-> [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a b. (a -> b) -> a -> b
$ [Tree (Value i a, st)] -> [Tree (Value i b, st)]
f [Tree (Value i a, st)]
xs
liftListWithTimeState :: (Time -> st -> [Tree (Value i a, st)] -> [Tree (Value i b, st)]) -> Cord st i a -> Cord st i b
liftListWithTimeState :: forall st i a b.
(Time -> st -> [Tree (Value i a, st)] -> [Tree (Value i b, st)])
-> Cord st i a -> Cord st i b
liftListWithTimeState Time -> st -> [Tree (Value i a, st)] -> [Tree (Value i b, st)]
f = (Time -> st -> Tree (Value i a, st) -> Tree (Value i b, st))
-> ZwirnT Tree st i a -> ZwirnT Tree st i b
forall st (k :: * -> *) i a b.
(Time -> st -> k (Value i a, st) -> k (Value i b, st))
-> ZwirnT k st i a -> ZwirnT k st i b
withInnerTimeState Time -> st -> Tree (Value i a, st) -> Tree (Value i b, st)
g
where
g :: Time -> st -> Tree (Value i a, st) -> Tree (Value i b, st)
g Time
t st
st (Leaf (Value i a, st)
x) = [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a. [Tree a] -> Tree a
Branch ([Tree (Value i b, st)] -> Tree (Value i b, st))
-> [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a b. (a -> b) -> a -> b
$ Time -> st -> [Tree (Value i a, st)] -> [Tree (Value i b, st)]
f Time
t st
st [(Value i a, st) -> Tree (Value i a, st)
forall a. a -> Tree a
Leaf (Value i a, st)
x]
g Time
t st
st (Branch [Tree (Value i a, st)]
xs) = [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a. [Tree a] -> Tree a
Branch ([Tree (Value i b, st)] -> Tree (Value i b, st))
-> [Tree (Value i b, st)] -> Tree (Value i b, st)
forall a b. (a -> b) -> a -> b
$ Time -> st -> [Tree (Value i a, st)] -> [Tree (Value i b, st)]
f Time
t st
st [Tree (Value i a, st)]
xs
instance HasSilence Tree where
silence :: forall st i a. ZwirnT Tree st i a
silence = (Time -> st -> Tree (Value i a, st)) -> ZwirnT Tree st i a
forall st (k :: * -> *) i a.
(Time -> st -> k (Value i a, st)) -> ZwirnT k st i a
zwirn ((Time -> st -> Tree (Value i a, st)) -> ZwirnT Tree st i a)
-> (Time -> st -> Tree (Value i a, st)) -> ZwirnT Tree st i a
forall a b. (a -> b) -> a -> b
$ (st -> Tree (Value i a, st)) -> Time -> st -> Tree (Value i a, st)
forall a b. a -> b -> a
const ((st -> Tree (Value i a, st))
-> Time -> st -> Tree (Value i a, st))
-> (st -> Tree (Value i a, st))
-> Time
-> st
-> Tree (Value i a, st)
forall a b. (a -> b) -> a -> b
$ Tree (Value i a, st) -> st -> Tree (Value i a, st)
forall a b. a -> b -> a
const (Tree (Value i a, st) -> st -> Tree (Value i a, st))
-> Tree (Value i a, st) -> st -> Tree (Value i a, st)
forall a b. (a -> b) -> a -> b
$ [Tree (Value i a, st)] -> Tree (Value i a, st)
forall a. [Tree a] -> Tree a
Branch []
depth :: Cord st i a -> Cord st i Int
depth :: forall st i a. Cord st i a -> Cord st i Int
depth = (Tree (Value i a, st) -> Tree (Value i Int, st))
-> ZwirnT Tree st i a -> ZwirnT Tree st i Int
forall (k :: * -> *) i a st b.
(k (Value i a, st) -> k (Value i b, st))
-> ZwirnT k st i a -> ZwirnT k st i b
withInner (\Tree (Value i a, st)
t -> (Value i a -> Value i Int) -> (Value i a, st) -> (Value i Int, st)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((a -> Int) -> Value i a -> Value i Int
forall a b. (a -> b) -> Value i a -> Value i b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> a -> Int
forall a b. a -> b -> a
const (Int -> a -> Int) -> Int -> a -> Int
forall a b. (a -> b) -> a -> b
$ Tree (Value i a, st) -> Int
forall a. Tree a -> Int
topLength Tree (Value i a, st)
t)) ((Value i a, st) -> (Value i Int, st))
-> Tree (Value i a, st) -> Tree (Value i Int, st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tree (Value i a, st)
t)
stack :: [Cord st i a] -> Cord st i a
stack :: forall st i a. [Cord st i a] -> Cord st i a
stack [Cord st i a]
zs = (Time -> st -> Tree (Value i a, st)) -> Cord st i a
forall st (k :: * -> *) i a.
(Time -> st -> k (Value i a, st)) -> ZwirnT k st i a
zwirn ((Time -> st -> Tree (Value i a, st)) -> Cord st i a)
-> (Time -> st -> Tree (Value i a, st)) -> Cord st i a
forall a b. (a -> b) -> a -> b
$ \Time
t st
st -> [Tree (Value i a, st)] -> Tree (Value i a, st)
forall a. [Tree a] -> Tree a
Branch ([Tree (Value i a, st)] -> Tree (Value i a, st))
-> [Tree (Value i a, st)] -> Tree (Value i a, st)
forall a b. (a -> b) -> a -> b
$ (Cord st i a -> Tree (Value i a, st))
-> [Cord st i a] -> [Tree (Value i a, st)]
forall a b. (a -> b) -> [a] -> [b]
map (\Cord st i a
x -> Cord st i a -> Time -> st -> Tree (Value i a, st)
forall (k :: * -> *) st i a.
ZwirnT k st i a -> Time -> st -> k (Value i a, st)
unzwirn Cord st i a
x Time
t st
st) [Cord st i a]
zs
project :: Cord st i Int -> Cord st i a -> Cord st i a
project :: forall st i a. Cord st i Int -> Cord st i a -> Cord st i a
project Cord st i Int
i Cord st i a
x = (Tree (Value i a, st) -> Tree (Value i a, st))
-> Cord st i a -> Cord st i a
forall (k :: * -> *) i a st b.
(k (Value i a, st) -> k (Value i b, st))
-> ZwirnT k st i a -> ZwirnT k st i b
withInner ((Tree (Value i a, st) -> Tree (Value i a, st))
-> Cord st i a -> Cord st i a)
-> (Int -> Tree (Value i a, st) -> Tree (Value i a, st))
-> Int
-> Cord st i a
-> Cord st i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Tree (Value i a, st) -> Tree (Value i a, st)
forall a. Int -> Tree a -> Tree a
look (Int -> Cord st i a -> Cord st i a)
-> Cord st i Int -> ZwirnT Tree st i (Cord st i a -> Cord st i a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cord st i Int
i ZwirnT Tree st i (Cord st i a -> Cord st i a)
-> Cord st i a -> Cord st i a
forall (m :: * -> *) a b. Monad m => m (m a -> m b) -> m a -> m b
<$$> Cord st i a
x
layer :: Cord st i (Cord st i a -> Cord st i b) -> Cord st i a -> Cord st i b
layer :: forall st i a b.
Cord st i (Cord st i a -> Cord st i b)
-> Cord st i a -> Cord st i b
layer Cord st i (Cord st i a -> Cord st i b)
fs Cord st i a
x = (Time -> st -> Tree (Value i b, st)) -> Cord st i b
forall st (k :: * -> *) i a.
(Time -> st -> k (Value i a, st)) -> ZwirnT k st i a
zwirn Time -> st -> Tree (Value i b, st)
q
where
q :: Time -> st -> Tree (Value i b, st)
q Time
t st
st = Tree (Tree (Value i b, st)) -> Tree (Value i b, st)
forall a. Tree (Tree a) -> Tree a
forall (m :: * -> *) a. MultiMonad m => m (m a) -> m a
squeezeJoin (Tree (Tree (Value i b, st)) -> Tree (Value i b, st))
-> Tree (Tree (Value i b, st)) -> Tree (Value i b, st)
forall a b. (a -> b) -> a -> b
$ (\Cord st i b
c -> Cord st i b -> Time -> st -> Tree (Value i b, st)
forall (k :: * -> *) st i a.
ZwirnT k st i a -> Time -> st -> k (Value i a, st)
unzwirn Cord st i b
c Time
t st
st) (Cord st i b -> Tree (Value i b, st))
-> ((Value i (Cord st i a -> Cord st i b), st) -> Cord st i b)
-> (Value i (Cord st i a -> Cord st i b), st)
-> Tree (Value i b, st)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Cord st i a -> Cord st i b) -> Cord st i a -> Cord st i b
forall a b. (a -> b) -> a -> b
$ Cord st i a
x) ((Cord st i a -> Cord st i b) -> Cord st i b)
-> ((Value i (Cord st i a -> Cord st i b), st)
-> Cord st i a -> Cord st i b)
-> (Value i (Cord st i a -> Cord st i b), st)
-> Cord st i b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value i (Cord st i a -> Cord st i b) -> Cord st i a -> Cord st i b
forall i a. Value i a -> a
value (Value i (Cord st i a -> Cord st i b)
-> Cord st i a -> Cord st i b)
-> ((Value i (Cord st i a -> Cord st i b), st)
-> Value i (Cord st i a -> Cord st i b))
-> (Value i (Cord st i a -> Cord st i b), st)
-> Cord st i a
-> Cord st i b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Value i (Cord st i a -> Cord st i b), st)
-> Value i (Cord st i a -> Cord st i b)
forall a b. (a, b) -> a
fst ((Value i (Cord st i a -> Cord st i b), st)
-> Tree (Value i b, st))
-> Tree (Value i (Cord st i a -> Cord st i b), st)
-> Tree (Tree (Value i b, st))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cord st i (Cord st i a -> Cord st i b)
-> Time -> st -> Tree (Value i (Cord st i a -> Cord st i b), st)
forall (k :: * -> *) st i a.
ZwirnT k st i a -> Time -> st -> k (Value i a, st)
unzwirn Cord st i (Cord st i a -> Cord st i b)
fs Time
t st
st
insert :: Cord st i Int -> Cord st i a -> Cord st i a -> Cord st i a
insert :: forall st i a.
Cord st i Int -> Cord st i a -> Cord st i a -> Cord st i a
insert Cord st i Int
ic Cord st i a
x Cord st i a
y = (((Cord st i a -> Cord st i a) -> Cord st i a -> Cord st i a
forall a b. (a -> b) -> a -> b
$ Cord st i a
y) ((Cord st i a -> Cord st i a) -> Cord st i a)
-> ((Cord st i a -> Cord st i a -> Cord st i a)
-> Cord st i a -> Cord st i a)
-> (Cord st i a -> Cord st i a -> Cord st i a)
-> Cord st i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Cord st i a -> Cord st i a -> Cord st i a)
-> Cord st i a -> Cord st i a -> Cord st i a
forall a b. (a -> b) -> a -> b
$ Cord st i a
x)) ((Cord st i a -> Cord st i a -> Cord st i a) -> Cord st i a)
-> (Int -> Cord st i a -> Cord st i a -> Cord st i a)
-> Int
-> Cord st i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Cord st i a -> Cord st i a -> Cord st i a
forall st i a. Int -> Cord st i a -> Cord st i a -> Cord st i a
insert' (Int -> Cord st i a) -> Cord st i Int -> Cord st i a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Cord st i Int
ic
where
insert' :: Int -> Cord st i a -> Cord st i a -> Cord st i a
insert' :: forall st i a. Int -> Cord st i a -> Cord st i a -> Cord st i a
insert' Int
i Cord st i a
x Cord st i a
ys = (Time -> st -> Tree (Value i a, st)) -> Cord st i a
forall st (k :: * -> *) i a.
(Time -> st -> k (Value i a, st)) -> ZwirnT k st i a
zwirn ((Time -> st -> Tree (Value i a, st)) -> Cord st i a)
-> (Time -> st -> Tree (Value i a, st)) -> Cord st i a
forall a b. (a -> b) -> a -> b
$ \Time
t st
st -> Int
-> Tree (Value i a, st)
-> Tree (Value i a, st)
-> Tree (Value i a, st)
forall a. Int -> Tree a -> Tree a -> Tree a
insertT Int
i (Cord st i a -> Time -> st -> Tree (Value i a, st)
forall (k :: * -> *) st i a.
ZwirnT k st i a -> Time -> st -> k (Value i a, st)
unzwirn Cord st i a
x Time
t st
st) (Cord st i a -> Time -> st -> Tree (Value i a, st)
forall (k :: * -> *) st i a.
ZwirnT k st i a -> Time -> st -> k (Value i a, st)
unzwirn Cord st i a
ys Time
t st
st)
remove :: Cord st i Int -> Cord st i a -> Cord st i a
remove :: forall st i a. Cord st i Int -> Cord st i a -> Cord st i a
remove Cord st i Int
i Cord st i a
x = (Tree (Value i a, st) -> Tree (Value i a, st))
-> Cord st i a -> Cord st i a
forall (k :: * -> *) i a st b.
(k (Value i a, st) -> k (Value i b, st))
-> ZwirnT k st i a -> ZwirnT k st i b
withInner ((Tree (Value i a, st) -> Tree (Value i a, st))
-> Cord st i a -> Cord st i a)
-> (Int -> Tree (Value i a, st) -> Tree (Value i a, st))
-> Int
-> Cord st i a
-> Cord st i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Tree (Value i a, st) -> Tree (Value i a, st)
forall a. Int -> Tree a -> Tree a
removeT (Int -> Cord st i a -> Cord st i a)
-> Cord st i Int -> ZwirnT Tree st i (Cord st i a -> Cord st i a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cord st i Int
i ZwirnT Tree st i (Cord st i a -> Cord st i a)
-> Cord st i a -> Cord st i a
forall (m :: * -> *) a b. Monad m => m (m a -> m b) -> m a -> m b
<$$> Cord st i a
x
at :: Cord st i Int -> Cord st i (Cord st i a -> Cord st i a) -> Cord st i a -> Cord st i a
at :: forall st i a.
Cord st i Int
-> Cord st i (Cord st i a -> Cord st i a)
-> Cord st i a
-> Cord st i a
at Cord st i Int
i Cord st i (Cord st i a -> Cord st i a)
f Cord st i a
x = Cord st i Int -> Cord st i a -> Cord st i a -> Cord st i a
forall st i a.
Cord st i Int -> Cord st i a -> Cord st i a -> Cord st i a
insert Cord st i Int
i (Cord st i (Cord st i a -> Cord st i a)
-> Cord st i a -> Cord st i a
forall (m :: * -> *) a b. Monad m => m (m a -> m b) -> m a -> m b
innerApply Cord st i (Cord st i a -> Cord st i a)
f (Cord st i a -> Cord st i a) -> Cord st i a -> Cord st i a
forall a b. (a -> b) -> a -> b
$ Cord st i Int -> Cord st i a -> Cord st i a
forall st i a. Cord st i Int -> Cord st i a -> Cord st i a
project Cord st i Int
i Cord st i a
x) (Cord st i Int -> Cord st i a -> Cord st i a
forall st i a. Cord st i Int -> Cord st i a -> Cord st i a
remove Cord st i Int
i Cord st i a
x)
arp :: Cord st i a -> Cord st i a
arp :: forall st i a. Cord st i a -> Cord st i a
arp = (Tree (Value i a, st) -> Tree (Value i a, st))
-> ZwirnT Tree st i a -> ZwirnT Tree st i a
forall (k :: * -> *) i a st b.
(k (Value i a, st) -> k (Value i b, st))
-> ZwirnT k st i a -> ZwirnT k st i b
withInner Tree (Value i a, st) -> Tree (Value i a, st)
forall i a st. Tree (Value i a, st) -> Tree (Value i a, st)
trans
where
trans :: Tree (Value i a, st) -> Tree (Value i a, st)
trans :: forall i a st. Tree (Value i a, st) -> Tree (Value i a, st)
trans (Leaf (Value i a, st)
x) = (Value i a, st) -> Tree (Value i a, st)
forall a. a -> Tree a
Leaf (Value i a, st)
x
trans (Branch []) = [Tree (Value i a, st)] -> Tree (Value i a, st)
forall a. [Tree a] -> Tree a
Branch []
trans (Branch [Tree (Value i a, st)]
xs) = [Tree (Value i a, st)] -> Tree (Value i a, st)
forall a. [Tree a] -> Tree a
Branch ([Tree (Value i a, st)] -> Tree (Value i a, st))
-> [Tree (Value i a, st)] -> Tree (Value i a, st)
forall a b. (a -> b) -> a -> b
$ (Int -> Tree (Value i a, st)) -> [Int] -> [Tree (Value i a, st)]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
i -> Int -> Int -> Tree (Value i a, st) -> Tree (Value i a, st)
forall i a st.
Int -> Int -> Tree (Value i a, st) -> Tree (Value i a, st)
shif ([Tree (Value i a, st)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Tree (Value i a, st)]
xs) Int
i ([Tree (Value i a, st)]
xs [Tree (Value i a, st)] -> Int -> Tree (Value i a, st)
forall a. HasCallStack => [a] -> Int -> a
!! Int
i)) [Int
0 .. [Tree (Value i a, st)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Tree (Value i a, st)]
xs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
where
shif :: Int -> Int -> Tree (Value i a, st) -> Tree (Value i a, st)
shif :: forall i a st.
Int -> Int -> Tree (Value i a, st) -> Tree (Value i a, st)
shif Int
total Int
i Tree (Value i a, st)
x = (Value i a -> Value i a) -> (Value i a, st) -> (Value i a, st)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (\Value i a
v -> Value i a
v {time = time v - fromIntegral i / fromIntegral total}) ((Value i a, st) -> (Value i a, st))
-> Tree (Value i a, st) -> Tree (Value i a, st)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tree (Value i a, st)
x
reverseC :: Cord st i a -> Cord st i a
reverseC :: forall st i a. Cord st i a -> Cord st i a
reverseC = ([Tree (Value i a, st)] -> [Tree (Value i a, st)])
-> Cord st i a -> Cord st i a
forall i a st b.
([Tree (Value i a, st)] -> [Tree (Value i b, st)])
-> Cord st i a -> Cord st i b
liftList [Tree (Value i a, st)] -> [Tree (Value i a, st)]
forall a. [a] -> [a]
reverse
rotateC :: Cord st i a -> Cord st i a
rotateC :: forall st i a. Cord st i a -> Cord st i a
rotateC = ([Tree (Value i a, st)] -> [Tree (Value i a, st)])
-> Cord st i a -> Cord st i a
forall i a st b.
([Tree (Value i a, st)] -> [Tree (Value i b, st)])
-> Cord st i a -> Cord st i b
liftList [Tree (Value i a, st)] -> [Tree (Value i a, st)]
forall a. [a] -> [a]
rotateList
where
rotateList :: [a] -> [a]
rotateList (a
x : [a]
xs) = [a]
xs [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
x]
invertC :: (Num a) => Cord st i a -> Cord st i a
invertC :: forall a st i. Num a => Cord st i a -> Cord st i a
invertC = ([Tree (Value i a, st)] -> [Tree (Value i a, st)])
-> Cord st i a -> Cord st i a
forall i a st b.
([Tree (Value i a, st)] -> [Tree (Value i b, st)])
-> Cord st i a -> Cord st i b
liftList [Tree (Value i a, st)] -> [Tree (Value i a, st)]
forall {p :: * -> * -> *} {f :: * -> *} {f :: * -> *} {b} {c}.
(Bifunctor p, Functor f, Functor f, Num b) =>
[f (p (f b) c)] -> [f (p (f b) c)]
invertList
where
invertList :: [f (p (f b) c)] -> [f (p (f b) c)]
invertList (f (p (f b) c)
x : [f (p (f b) c)]
xs) = [f (p (f b) c)]
xs [f (p (f b) c)] -> [f (p (f b) c)] -> [f (p (f b) c)]
forall a. [a] -> [a] -> [a]
++ [(p (f b) c -> p (f b) c) -> f (p (f b) c) -> f (p (f b) c)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((f b -> f b) -> p (f b) c -> p (f b) c
forall a b c. (a -> b) -> p a c -> p b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ((f b -> f b) -> p (f b) c -> p (f b) c)
-> (f b -> f b) -> p (f b) c -> p (f b) c
forall a b. (a -> b) -> a -> b
$ (b -> b) -> f b -> f b
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (b -> b -> b
forall a. Num a => a -> a -> a
+ b
12)) f (p (f b) c)
x]
enumFromToStack :: (Ord a, Num a) => Cord st i a -> Cord st i a -> Cord st i a
enumFromToStack :: forall a st i.
(Ord a, Num a) =>
Cord st i a -> Cord st i a -> Cord st i a
enumFromToStack Cord st i a
xz Cord st i a
yz = ZwirnT Tree st i (Cord st i a) -> Cord st i a
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (ZwirnT Tree st i (Cord st i a) -> Cord st i a)
-> ZwirnT Tree st i (Cord st i a) -> Cord st i a
forall a b. (a -> b) -> a -> b
$ a -> a -> Cord st i a
forall {a} {st} {i}. (Ord a, Num a) => a -> a -> Cord st i a
en (a -> a -> Cord st i a)
-> Cord st i a -> ZwirnT Tree st i (a -> Cord st i a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cord st i a
xz ZwirnT Tree st i (a -> Cord st i a)
-> Cord st i a -> ZwirnT Tree st i (Cord st i a)
forall a b.
ZwirnT Tree st i (a -> b)
-> ZwirnT Tree st i a -> ZwirnT Tree st i b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Cord st i a
yz
where
en :: a -> a -> Cord st i a
en a
x a
y = [Cord st i a] -> Cord st i a
forall st i a. [Cord st i a] -> Cord st i a
stack ([Cord st i a] -> Cord st i a) -> [Cord st i a] -> Cord st i a
forall a b. (a -> b) -> a -> b
$ (a -> Cord st i a) -> [a] -> [Cord st i a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Cord st i a
forall a. a -> ZwirnT Tree st i a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([a] -> [Cord st i a]) -> [a] -> [Cord st i a]
forall a b. (a -> b) -> a -> b
$ a -> a -> [a]
forall a. (Ord a, Num a) => a -> a -> [a]
enumerateFromTo a
x a
y
enumFromThenToStack :: (Ord a, Num a) => Cord st i a -> Cord st i a -> Cord st i a -> Cord st i a
enumFromThenToStack :: forall a st i.
(Ord a, Num a) =>
Cord st i a -> Cord st i a -> Cord st i a -> Cord st i a
enumFromThenToStack Cord st i a
xz Cord st i a
yz Cord st i a
zz = ZwirnT Tree st i (Cord st i a) -> Cord st i a
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (ZwirnT Tree st i (Cord st i a) -> Cord st i a)
-> ZwirnT Tree st i (Cord st i a) -> Cord st i a
forall a b. (a -> b) -> a -> b
$ a -> a -> a -> Cord st i a
forall {a} {st} {i}. (Ord a, Num a) => a -> a -> a -> Cord st i a
en (a -> a -> a -> Cord st i a)
-> Cord st i a -> ZwirnT Tree st i (a -> a -> Cord st i a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cord st i a
xz ZwirnT Tree st i (a -> a -> Cord st i a)
-> Cord st i a -> ZwirnT Tree st i (a -> Cord st i a)
forall a b.
ZwirnT Tree st i (a -> b)
-> ZwirnT Tree st i a -> ZwirnT Tree st i b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Cord st i a
yz ZwirnT Tree st i (a -> Cord st i a)
-> Cord st i a -> ZwirnT Tree st i (Cord st i a)
forall a b.
ZwirnT Tree st i (a -> b)
-> ZwirnT Tree st i a -> ZwirnT Tree st i b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Cord st i a
zz
where
en :: a -> a -> a -> Cord st i a
en a
x a
y a
z = [Cord st i a] -> Cord st i a
forall st i a. [Cord st i a] -> Cord st i a
stack ([Cord st i a] -> Cord st i a) -> [Cord st i a] -> Cord st i a
forall a b. (a -> b) -> a -> b
$ (a -> Cord st i a) -> [a] -> [Cord st i a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Cord st i a
forall a. a -> ZwirnT Tree st i a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([a] -> [Cord st i a]) -> [a] -> [Cord st i a]
forall a b. (a -> b) -> a -> b
$ a -> a -> a -> [a]
forall a. (Ord a, Num a) => a -> a -> a -> [a]
enumerateFromThenTo a
x a
y a
z