Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: bf54cd635d
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 30 lines (23 sloc) 0.623 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

-- we want to fold something like this
g = [
    [ 1, 2, 3 ],
    [ 4, 5, 6 ],
    [ 7, 8, 9 ]
    ]

-- into a Cell { value=1, right=(the Cell with value 2), down=(the cell with value 4) }

data Cell a = Cell {
    value :: a,
    down :: Cell a,
    right :: Cell a
    }
    | Nil
    deriving Show

right' :: Cell a -> Cell a
right' c@(Cell {}) = right c
right' Nil = Nil

mkRow :: [a] -> Cell a -> Cell a
mkRow xs c = foldr mkCell Nil valAndDown
    where valAndDown = zip xs (iterate right' c)
          mkCell (v,d) r = Cell { value=v, down=d, right=r }

mkGrid :: [[a]] -> Cell a
mkGrid = foldr mkRow Nil
Something went wrong with that request. Please try again.