From 899ad0ed13d3e347e2818294f7ed9d8d4d468e94 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 4 Dec 2023 20:10:18 -0600 Subject: refactor: Lattice -> World.Lattice --- nerine.cabal | 2 +- src/Lattice.hs | 23 ----------------------- src/World/Lattice.hs | 23 +++++++++++++++++++++++ src/World/Types.hs | 2 +- test/LatticeTest.hs | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 src/Lattice.hs create mode 100644 src/World/Lattice.hs diff --git a/nerine.cabal b/nerine.cabal index 903ef49..8f4f443 100644 --- a/nerine.cabal +++ b/nerine.cabal @@ -27,10 +27,10 @@ library exposed-modules: Agent Genome - Lattice Lib Mind Proposal + World.Lattice World.Types other-modules: Paths_nerine diff --git a/src/Lattice.hs b/src/Lattice.hs deleted file mode 100644 index b69aa41..0000000 --- a/src/Lattice.hs +++ /dev/null @@ -1,23 +0,0 @@ -module Lattice - ( LatticeCell (..) - , Lattice - , LatticeRule - , updateLattice - ) where - - -data LatticeCell a b = LatticeCell { kind :: a, flags :: b } deriving (Show, Eq) -type Lattice a b = [[LatticeCell a b]] -type LatticeRule a b = Lattice a b -> Int -> Int -> LatticeCell a b - - -updateLattice :: (Enum a) => Lattice a b -> [LatticeRule a b] -> Lattice a b -updateLattice lattice rules = - let - mapRow = \(row, y) -> map - (\((LatticeCell k _), x) -> - let rule = rules !! (fromEnum k) - in rule lattice x y - ) - (zip row [0..]) - in map mapRow (zip lattice [0..]) diff --git a/src/World/Lattice.hs b/src/World/Lattice.hs new file mode 100644 index 0000000..257ea50 --- /dev/null +++ b/src/World/Lattice.hs @@ -0,0 +1,23 @@ +module World.Lattice + ( LatticeCell (..) + , Lattice + , LatticeRule + , updateLattice + ) where + + +data LatticeCell a b = LatticeCell { kind :: a, flags :: b } deriving (Show, Eq) +type Lattice a b = [[LatticeCell a b]] +type LatticeRule a b = Lattice a b -> Int -> Int -> LatticeCell a b + + +updateLattice :: (Enum a) => Lattice a b -> [LatticeRule a b] -> Lattice a b +updateLattice lattice rules = + let + mapRow = \(row, y) -> map + (\((LatticeCell k _), x) -> + let rule = rules !! (fromEnum k) + in rule lattice x y + ) + (zip row [0..]) + in map mapRow (zip lattice [0..]) diff --git a/src/World/Types.hs b/src/World/Types.hs index e9be991..78bd5af 100644 --- a/src/World/Types.hs +++ b/src/World/Types.hs @@ -104,6 +104,6 @@ instance (Combinable a) => Combinable (AgentPropList a) where newtype Proposal a b c = Proposal (LatticePropList a b, AgentPropList c) deriving (Show, Eq) instance (Combinable a, Combinable b, Combinable c) => Combinable (Proposal a b c) where - identity = Proposal ([], []) + identity = Proposal (LatticePropList [], AgentPropList []) combinable (Proposal (l, a)) (Proposal (l', a')) = (combinable l l') && (combinable a a') combine (Proposal (l, a)) (Proposal (l', a')) = Proposal (combine l l', combine a a') diff --git a/test/LatticeTest.hs b/test/LatticeTest.hs index a7d67d8..403c650 100644 --- a/test/LatticeTest.hs +++ b/test/LatticeTest.hs @@ -2,7 +2,7 @@ module LatticeTest (suite) where import Test.Tasty import Test.Tasty.HUnit -import Lattice +import World.Lattice suite :: TestTree suite = testGroup "lattice tests" $ -- cgit v1.2.1