Add new function to print a grid

This commit is contained in:
Rnhmjoj 2014-12-19 20:24:16 +01:00
parent 248e364f39
commit 5bae8c5796

View File

@ -3,6 +3,13 @@ import Matrix
type Cell = Int
type Grid = Mat Cell
-- | Print a grid
gprint :: Grid -> IO ()
gprint = putStrLn . map replace . show
where
replace '1' = '■'
replace '0' = '.'
replace a = a
-- | Get the state of a cell
-- 0 when out of the grid
@ -31,7 +38,7 @@ next :: Grid -> Grid
next g = fmap (alive g) (indeces g)
main :: IO ()
main = mapM_ print (iterate next grid)
main = mapM_ gprint (iterate next grid)
grid = Mat [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]