From e064dc26393bf65a031aca6f22c33ab19e912a81 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Tue, 21 Dec 2021 22:05:08 -0500 Subject: [PATCH] Add GOL constructors --- GOL/Engine.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GOL/Engine.hs b/GOL/Engine.hs index 9e97178..fd3b6a1 100644 --- a/GOL/Engine.hs +++ b/GOL/Engine.hs @@ -4,8 +4,10 @@ module GOL.Engine where import Control.Comonad.Env +import Control.Comonad.Identity (Identity (Identity)) import Control.Comonad.Representable.Store import Data.Bool (bool) +import Data.Functor.Rep import GOL.Rule import GOL.Space @@ -14,6 +16,16 @@ import GOL.Space -- with an environment containing a rule. type GOL f = EnvT Rule (Store f) +-- | Construct a 'GOL' value given a rule, a board +-- state, and an initial position. +gol :: Rule -> Rep f -> f a -> GOL f a +gol r p s = EnvT r $ StoreT (Identity s) p + +-- | Construct a 'GOL' value on a displayable space, +-- defaulting to an initial position of @(0, 0)@. +gol' :: DisplayableSpace f => Rule -> f a -> GOL f a +gol' r = gol r (0,0) + getNeighbors :: forall f a. Space f => GOL f a -> [a] getNeighbors = experiment $ neighbors @f