Create GOL.Rule

This commit is contained in:
Kiana Sheibani 2021-12-20 00:59:04 -05:00
parent 51c91a0b9b
commit 96cccfe750
3 changed files with 30 additions and 2 deletions

26
GOL/Rule.hs Normal file
View file

@ -0,0 +1,26 @@
module GOL.Rule where
-- | The rule of a Conway's Game of Life simulation
-- describes how a cell changes based on its surrounding
-- cells. The official GOL uses one standard rule, but
-- this engine allows for an arbitrary rule to be applied.
--
-- A rule consists of two predicates that take a value
-- in the range [0..8], the count of alive cells neighboring
-- the current cell, and returns whether that cell will be
-- alive in the next generation.
data Rule = Rule
{
-- | A predicate deciding if an alive cell
-- will be alive in the next generation.
survive :: Int -> Bool,
-- | A predicate deciding if a dead cell
-- will be alive in the next generation.
birth :: Int -> Bool
}
-- | The standard GOL rule (S23/B3).
standardRule :: Rule
standardRule = Rule (`elem` [2,3]) (== 3)

View file

@ -1,4 +1,5 @@
module Main where
main :: IO ()
main = putStrLn "Hello"

View file

@ -8,5 +8,6 @@ cabal-version: >= 1.8
executable main
build-depends: base,
comonad
comonad,
Yampa
main-is: Main.hs