module ShapeContents where
import Neume.Core.Utils
import Neume.Core.Utils.HList
elementary :: (a -> b) -> [[a]] -> [[b]]
elementary f xss = reassemble (map f contents) shape
where
(shape, contents) = decompose xss
decompose :: [[a]] -> ([[()]],[a])
decompose xss = fmap2b ($ []) $ stmap fn id xss
where
fn stf row = (row1, stf . h1) where (row1,h1) = decompose1 row
decompose1 :: StateMap f => f a -> (f (), H a)
decompose1 = stmap fn id where
fn stf a = ((), stf `snoc` a)
reassemble :: [a] -> [[()]] -> [[a]]
reassemble xs shape = fst $ stmap (stmap fn) xs shape where
fn (s:st) () = (s,st)
fn _ () = error $ "reassemble - run out of data"
Tuesday, April 13, 2010
Shape contents traversal...
Here's a bit of code using Neume's StateMap class an a Hughes list that separates the shape of data from its contents. In the code here elementary could also be coded as map (map f), but more inventive "elemenentary" functions are possible.
Blog Archive
-
▼
2010
(890)
-
▼
April
(82)
- utt
- precis-0.3.1
- Precis
- precis-0.2.0
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- Precis
- bala-core
- bala-core
- A DSEL for manipulating meter patterns
- Charcoal
- Charcoal
- Charcoal
- bala-core
- bala-core
- wumpus-core
- bala-core
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Shape contents traversal...
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Type level success?
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
- precis-0.1.0
- Neume
- Neume
- Neume
- Neume
- Neume
- Neume
-
▼
April
(82)
About Me
- Stephen Tetley
- Disambiguating biog as there are a few Stephen Tetley's in the world. I'm neither a cage fighter or yachtsman. I studied Fine Art in the nineties (foundation Bradford 1992, degree Cheltenham 1992 - 95) then Computing part-time at Leeds Met graduating in 2003. I'm the Stephen Tetley on Haskell Cafe and Stackoverflow.