osfameron / misc-opensource
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
bf54cd6
hakim (author)
Mon Mar 09 17:50:25 -0700 2009
| 6e4bcea8 » | hakim | 2009-03-09 | 1 | -- we want to fold something like this | |
| 2 | g = [ | ||||
| 3 | [ 1, 2, 3 ], | ||||
| 4 | [ 4, 5, 6 ], | ||||
| 5 | [ 7, 8, 9 ] | ||||
| 6 | ] | ||||
| 7 | |||||
| 8 | -- into a Cell { value=1, right=(the Cell with value 2), down=(the cell with value 4) } | ||||
| 9 | |||||
| 10 | data Cell a = Cell { | ||||
| 11 | value :: a, | ||||
| 12 | down :: Cell a, | ||||
| 13 | right :: Cell a | ||||
| 14 | } | ||||
| 15 | | Nil | ||||
| 16 | deriving Show | ||||
| 17 | |||||
| 18 | right' :: Cell a -> Cell a | ||||
| 19 | right' c@(Cell {}) = right c | ||||
| 20 | right' Nil = Nil | ||||
| 21 | |||||
| 22 | mkRow :: [a] -> Cell a -> Cell a | ||||
| bf54cd63 » | hakim | 2009-03-09 | 23 | mkRow xs c = foldr mkCell Nil valAndDown | |
| 24 | where valAndDown = zip xs (iterate right' c) | ||||
| 6e4bcea8 » | hakim | 2009-03-09 | 25 | mkCell (v,d) r = Cell { value=v, down=d, right=r } | |
| 26 | |||||
| 27 | mkGrid :: [[a]] -> Cell a | ||||
| bf54cd63 » | hakim | 2009-03-09 | 28 | mkGrid = foldr mkRow Nil | |
| 29 | |||||
