diff options
Diffstat (limited to 'src/Network.hs')
-rw-r--r-- | src/Network.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Network.hs b/src/Network.hs index 5872d13..a3c7120 100644 --- a/src/Network.hs +++ b/src/Network.hs @@ -2,6 +2,7 @@ module Network ( Network(..), Node(..), NodeName(..), textNodeName, unpackNodeName, + nextNodeName, ) where import Control.Arrow @@ -26,20 +27,28 @@ data Node = Node , nodeDir :: FilePath } -newtype NodeName = NodeName Text +data NodeName = NodeName Text Word deriving (Eq, Ord) textNodeName :: NodeName -> Text -textNodeName (NodeName name) = name +textNodeName (NodeName name 0) = name +textNodeName (NodeName name num) = name <> T.pack "~" <> T.pack (show num) unpackNodeName :: NodeName -> String -unpackNodeName (NodeName tname) = T.unpack tname +unpackNodeName = T.unpack . textNodeName + +nextNodeName :: VarName -> [NodeName] -> NodeName +nextNodeName (VarName tname) = go 0 + where + go n [] = NodeName tname n + go n (NodeName tname' m : ns) | tname == tname' = go (max n m + 1) ns + | otherwise = go n ns instance ExprType Node where textExprType _ = T.pack "node" textExprValue n = T.pack "n:" <> textNodeName (nodeName n) - emptyVarValue = Node (NodeName T.empty) T.empty undefined undefined + emptyVarValue = Node (NodeName T.empty 0) T.empty undefined undefined recordMembers = map (first T.pack) [ ("ip", RecordSelector $ nodeIp) |