From 5bae8c57960288715dcc530eb2b0b2dac8f5a3b6 Mon Sep 17 00:00:00 2001 From: Rnhmjoj Date: Fri, 19 Dec 2014 20:24:16 +0100 Subject: [PATCH] Add new function to print a grid --- life.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/life.hs b/life.hs index 835d622..3afe060 100644 --- a/life.hs +++ b/life.hs @@ -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]