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 --- src/Lattice.hs | 23 ----------------------- src/World/Lattice.hs | 23 +++++++++++++++++++++++ src/World/Types.hs | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) delete mode 100644 src/Lattice.hs create mode 100644 src/World/Lattice.hs (limited to 'src') 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') -- cgit v1.2.1