module Generics.Pointless.Examples.Observe where
import Generics.Pointless.Combinators
import Generics.Pointless.Functors
import Generics.Pointless.RecursionPatterns
import Generics.Pointless.Observe.RecursionPatterns
import Generics.Pointless.Observe.Functors
import Generics.Pointless.Examples.Examples
import Debug.Observe
import Data.Typeable
lengthHyloO :: Observable a => [a] -> Int
lengthHyloO = hyloO (ann::Ann Int) f g
where f = inn
g = (id -|- snd) . out
lengthAnaO :: Observable a => [a] -> Int
lengthAnaO = anaO (ann::Ann Int) f
where f = (id -|- snd) . out
lengthCataO :: (Typeable a, Observable a) => [a] -> Int
lengthCataO = cataO (ann ::Ann [a]) g
where g = inn . (id -|- snd)
factHyloO :: Int -> Int
factHyloO = hyloO (ann::Ann [Int]) f g
where g = (id -|- succ /\ id) . out
f = one \/ prod
factParaO :: Int -> Int
factParaO = paraO (ann::Ann Int) f
where f = one \/ prod . (id >< succ)
factZygoO :: Int -> Int
factZygoO = zygoO (ann::Ann Int) inn f
where f = one \/ (prod . (id >< succ))
fibHyloO :: Int -> Int
fibHyloO = hyloO (ann::Ann (LTree One)) f g
where g = (bang -|- pred /\ pred . pred) . ((<=1)?)
f = one \/ add
fibHistoO :: Int -> Int
fibHistoO = histoO (ann::Ann Int) f
where f = (zero \/ (one . snd \/ add . (id >< outl)) . distr . out)
fibDynaO :: Int -> Int
fibDynaO = dynaO (ann::Ann Int) f g
where f = (zero \/ (one . snd \/ add . (id >< outl)) . distr . out)
g = out
qsortHyloO :: (Typeable a, Observable a, Ord a) => [a] -> [a]
qsortHyloO = hyloO (ann::Ann (Tree a)) f g
where g = (id -|- fst /\ partition) . out
f = nil \/ cat . (id >< cons) . assocr . (swap >< id) . assocl
tailParaO :: (Typeable a, Observable a) => [a] -> [a]
tailParaO = paraO (ann::Ann [a]) (nil \/ snd . snd)
addAccumO :: (Int,Int) -> Int
addAccumO = accumO (ann::Ann Int) t f
where t = (fst -|- id >< succ) . distl
f = (snd \/ fst) . distl