diff options
author | sanine <sanine.not@pm.me> | 2023-11-30 13:54:44 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-30 13:54:44 -0600 |
commit | bf40a269daef0517e2d0fc5961e043ece6ff4837 (patch) | |
tree | 4d337ed89a9ccebf03f815adbab7406e8d98978f /src/World | |
parent | 587cbadb3e6388c29454ab41c120757f108918fa (diff) |
begin adding world types
Diffstat (limited to 'src/World')
-rw-r--r-- | src/World/.Types.hs.swo | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | src/World/Types.hs | 61 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/World/.Types.hs.swo b/src/World/.Types.hs.swo Binary files differnew file mode 100644 index 0000000..527fc99 --- /dev/null +++ b/src/World/.Types.hs.swo diff --git a/src/World/Types.hs b/src/World/Types.hs new file mode 100644 index 0000000..c7f77ce --- /dev/null +++ b/src/World/Types.hs @@ -0,0 +1,61 @@ +module World.Types + ( Merge (..) + , Pos + , LatticeProposal (..) + , AgentProposal (..) + , Proposal (..) + ) where + + +class Merge a where + mergeCompatible :: a -> a -> Bool + merge :: a -> a -> a + +instance (Merge a) => Merge (Maybe a) where + mergeCompatible (Just x) (Just y) = mergeCompatible x y + mergeCompatible _ _ = True + merge (Just x) (Just y) = Just $ merge x y + merge Nothing (Just y) = Just $ y + merge (Just x) (Nothing) = Just $ x + merge Nothing Nothing = Nothing + +class (Eq a) => MergeEq a where + mergeEqCompatible :: a -> a -> Bool + mergeEq :: a -> a -> a + +instance (Eq a) => MergeEq (Maybe a) where + mergeEqCompatible (Just x) (Just y) = x == y + mergeEqCompatible _ _ = True + mergeEq (Just x) (Just _) = Just $ x + mergeEq Nothing (Just y) = Just $ y + mergeEq (Just x) (Nothing) = Just $ x + mergeEq Nothing Nothing = Nothing + +type Pos = (Int, Int) + +data LatticeProposal a b = LatticeProposal + { cellPos :: Pos + , from :: Maybe a + , to :: Maybe a + , cellFlags :: Maybe b + } + deriving (Show, Eq) + +data AgentProposal a = AgentProposal + { id :: Int + , agentPos :: Pos + , agentFlags :: a + } + deriving (Show, Eq) + +newtype Proposal a b c = Proposal ([LatticeProposal a b], [AgentProposal c]) deriving (Show, Eq) + + +instance (Eq a, Merge b) => Merge (LatticeProposal a b) where + mergeCompatible x y = + if (cellPos x /= cellPos y) then True else + if mergeEqCompatible (from x) (from y) + && mergeEqCompatible (to x) (to y) + && mergeCompatible (cellFlags x) (cellFlags y) + then True + else False |