module Sound.Tidal.Bjorklund (bjorklund) where
type STEP a = ((Int,Int),([[a]],[[a]]))
left :: STEP a -> STEP a
left :: forall a. STEP a -> STEP a
left ((Int
i,Int
j),([[a]]
xs,[[a]]
ys)) =
let ([[a]]
xs',[[a]]
xs'') = forall a. Int -> [a] -> ([a], [a])
splitAt Int
j [[a]]
xs
in ((Int
j,Int
iforall a. Num a => a -> a -> a
-Int
j),(forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. [a] -> [a] -> [a]
(++) [[a]]
xs' [[a]]
ys,[[a]]
xs''))
right :: STEP a -> STEP a
right :: forall a. STEP a -> STEP a
right ((Int
i,Int
j),([[a]]
xs,[[a]]
ys)) =
let ([[a]]
ys',[[a]]
ys'') = forall a. Int -> [a] -> ([a], [a])
splitAt Int
i [[a]]
ys
in ((Int
i,Int
jforall a. Num a => a -> a -> a
-Int
i),(forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. [a] -> [a] -> [a]
(++) [[a]]
xs [[a]]
ys',[[a]]
ys''))
bjorklund' :: STEP a -> STEP a
bjorklund' :: forall a. STEP a -> STEP a
bjorklund' ((Int, Int)
n,([[a]], [[a]])
x) =
let (Int
i,Int
j) = (Int, Int)
n
in if forall a. Ord a => a -> a -> a
min Int
i Int
j forall a. Ord a => a -> a -> Bool
<= Int
1
then ((Int, Int)
n,([[a]], [[a]])
x)
else forall a. STEP a -> STEP a
bjorklund' (if Int
i forall a. Ord a => a -> a -> Bool
> Int
j then forall a. STEP a -> STEP a
left ((Int, Int)
n,([[a]], [[a]])
x) else forall a. STEP a -> STEP a
right ((Int, Int)
n,([[a]], [[a]])
x))
bjorklund :: (Int,Int) -> [Bool]
bjorklund :: (Int, Int) -> [Bool]
bjorklund (Int
i,Int
j') =
let j :: Int
j = Int
j' forall a. Num a => a -> a -> a
- Int
i
x :: [[Bool]]
x = forall a. Int -> a -> [a]
replicate Int
i [Bool
True]
y :: [[Bool]]
y = forall a. Int -> a -> [a]
replicate Int
j [Bool
False]
((Int, Int)
_,([[Bool]]
x',[[Bool]]
y')) = forall a. STEP a -> STEP a
bjorklund' ((Int
i,Int
j),([[Bool]]
x,[[Bool]]
y))
in forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Bool]]
x' forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Bool]]
y'