makeComp parts _ chans (InstanceComp _compNo partName ports links _) = do
        let
            parentLinks :: [Chan]
            parentLinks = flattenSome $ Some $ map (fmap (chans DM.!)) links
            Just part = nwFindPart parts partName

            connectLink port parentLink instanceLink = withLabel (nwPortName port) $ body
                (directionToSense $ nwPortDirection port) parentLink instanceLink
                where
                    body Passive ((chanLinkPR, chanLinkPA), _) (_, (portLinkAR, portLinkAA)) = do
                        withLabel "r" $ newTrans [chanLinkPR] [portLinkAR] [PNInput 0]
                        withLabel "a" $ newTrans [portLinkAA] [chanLinkPA] [PNLiteral token]
                    body Active (_, (chanLinkAR, chanLinkAA)) ((portLinkPR, portLinkPA), _) = do
                        withLabel "r" $ newTrans [portLinkPR] [chanLinkAR] [PNInput 0]
                        withLabel "a" $ newTrans [chanLinkAA] [portLinkPA] [PNLiteral token]
        instanceLinks <- makePartPN parts part
        withLabel (networkName part) $ withLabel "port" $ do
            mapM_ (uncurry3 connectLink) $ zip3 ports parentLinks instanceLinks
makeComp parts _ chans (InstanceComp _compNo partName ports links _) = do
        let
            parentLinks :: [Chan]
            parentLinks = flattenSome $ Some $ map (fmap (chans DM.!)) links
            Just part = nwFindPart parts partName

            connectLink port parentLink instanceLink = withLabel (nwPortName port) $ body
                (directionToSense $ nwPortDirection port) parentLink instanceLink
                where
                    body Passive ((chanLinkPR, chanLinkPA), _) (_, (portLinkAR, portLinkAA)) = do
                        withLabel "r" $ newTrans [chanLinkPR] [portLinkAR] [PNInput 0]
                        withLabel "a" $ newTrans [portLinkAA] [chanLinkPA] [PNLiteral token]
                    body Active (_, (chanLinkAR, chanLinkAA)) ((portLinkPR, portLinkPA), _) = do
                        withLabel "r" $ newTrans [portLinkPR] [chanLinkAR] [PNInput 0]
                        withLabel "a" $ newTrans [chanLinkAA] [portLinkPA] [PNLiteral token]
        instanceLinks <- makePartPN parts part
        withLabel (networkName part) $ withLabel "port" $ do
            mapM_ (uncurry3 connectLink) $ zip3 ports parentLinks instanceLinks
makeComp parts _ chans (InstanceComp _compNo partName ports links _) = do
        let
            parentLinks :: [Chan]
            parentLinks = flattenSome $ Some $ map (fmap (chans DM.!)) links
            Just part = nwFindPart parts partName

            connectLink port parentLink instanceLink = withLabel (nwPortName port) $ body
                (directionToSense $ nwPortDirection port) parentLink instanceLink
                where
                    body Passive ((chanLinkPR, chanLinkPA), _) (_, (portLinkAR, portLinkAA)) = do
                        withLabel "r" $ newTrans [chanLinkPR] [portLinkAR] [PNInput 0]
                        withLabel "a" $ newTrans [portLinkAA] [chanLinkPA] [PNLiteral token]
                    body Active (_, (chanLinkAR, chanLinkAA)) ((portLinkPR, portLinkPA), _) = do
                        withLabel "r" $ newTrans [portLinkPR] [chanLinkAR] [PNInput 0]
                        withLabel "a" $ newTrans [chanLinkAA] [portLinkPA] [PNLiteral token]
        instanceLinks <- makePartPN parts part
        withLabel (networkName part) $ withLabel "port" $ do
            mapM_ (uncurry3 connectLink) $ zip3 ports parentLinks instanceLinks