Add GOL constructors
This commit is contained in:
parent
12c28cd733
commit
e064dc2639
|
@ -4,8 +4,10 @@
|
||||||
module GOL.Engine where
|
module GOL.Engine where
|
||||||
|
|
||||||
import Control.Comonad.Env
|
import Control.Comonad.Env
|
||||||
|
import Control.Comonad.Identity (Identity (Identity))
|
||||||
import Control.Comonad.Representable.Store
|
import Control.Comonad.Representable.Store
|
||||||
import Data.Bool (bool)
|
import Data.Bool (bool)
|
||||||
|
import Data.Functor.Rep
|
||||||
import GOL.Rule
|
import GOL.Rule
|
||||||
import GOL.Space
|
import GOL.Space
|
||||||
|
|
||||||
|
@ -14,6 +16,16 @@ import GOL.Space
|
||||||
-- with an environment containing a rule.
|
-- with an environment containing a rule.
|
||||||
type GOL f = EnvT Rule (Store f)
|
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 :: forall f a. Space f => GOL f a -> [a]
|
||||||
getNeighbors = experiment $ neighbors @f
|
getNeighbors = experiment $ neighbors @f
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue