connect :: Serializable b => Shell a (tag b) -> Shell (tag b) c -> DNA ()
connect (Shell childA _ sendEnd) (Shell childB recvEnd _) = do
    case (sendEnd,recvEnd) of
      -- Val
      (SendVal chDst, RecvVal chB) -> do
          -- FIXME: Do we want to allow unsafe send here?
          liftP $ sendChan chDst $ SendRemote [chB]
          sendACP $ ReqConnect childA childB []
      (SendVal chDst, RecvBroadcast (RecvGrp chans)) -> do
          liftP $ sendChan chDst $ SendRemote chans
          sendACP $ ReqConnect childA childB []
      -- Grp
      (SendGrp chDst, RecvReduce chReduce) -> do
          let chB = map snd chReduce
          liftP $ forM_ chDst $ \ch -> sendChan ch $ SendRemote chB
          sendACP $ ReqConnect childA childB [chN | (chN,_) <- chReduce ]
      -- MR
      (SendMR chDst, RecvMR chans) -> do
          let chB = map snd chans
          liftP $ forM_ chDst $ \ch -> sendChan ch chB
          sendACP $ ReqConnect childA childB [chN | (chN,_) <- chans]
      -- IMPOSSIBLE
      --
      -- GHC cannot understand that pattern match is exhaustive
      _ -> error "Impossible: pattern match is not exhaustive"



----------------------------------------------------------------
-- Promises
----------------------------------------------------------------
connect :: Serializable b => Shell a (tag b) -> Shell (tag b) c -> DNA ()
connect (Shell childA _ sendEnd) (Shell childB recvEnd _) = do
    case (sendEnd,recvEnd) of
      -- Val
      (SendVal chDst, RecvVal chB) -> do
          -- FIXME: Do we want to allow unsafe send here?
          liftP $ sendChan chDst $ SendRemote [chB]
          sendACP $ ReqConnect childA childB []
      (SendVal chDst, RecvBroadcast (RecvGrp chans)) -> do
          liftP $ sendChan chDst $ SendRemote chans
          sendACP $ ReqConnect childA childB []
      -- Grp
      (SendGrp chDst, RecvReduce chReduce) -> do
          let chB = map snd chReduce
          liftP $ forM_ chDst $ \ch -> sendChan ch $ SendRemote chB
          sendACP $ ReqConnect childA childB [chN | (chN,_) <- chReduce ]
      -- MR
      (SendMR chDst, RecvMR chans) -> do
          let chB = map snd chans
          liftP $ forM_ chDst $ \ch -> sendChan ch chB
          sendACP $ ReqConnect childA childB [chN | (chN,_) <- chans]
      -- IMPOSSIBLE
      --
      -- GHC cannot understand that pattern match is exhaustive
      _ -> error "Impossible: pattern match is not exhaustive"



----------------------------------------------------------------
-- Promises
----------------------------------------------------------------
connect (Shell childA _ sendEnd) (Shell childB recvEnd _) = do
    case (sendEnd,recvEnd) of
      -- Val
      (SendVal chDst, RecvVal chB) -> do
          -- FIXME: Do we want to allow unsafe send here?
          liftP $ sendChan chDst $ SendRemote [chB]
          sendACP $ ReqConnect childA childB []
      (SendVal chDst, RecvBroadcast (RecvGrp chans)) -> do
          liftP $ sendChan chDst $ SendRemote chans
          sendACP $ ReqConnect childA childB []
      -- Grp
      (SendGrp chDst, RecvReduce chReduce) -> do
          let chB = map snd chReduce
          liftP $ forM_ chDst $ \ch -> sendChan ch $ SendRemote chB
          sendACP $ ReqConnect childA childB [chN | (chN,_) <- chReduce ]
      -- MR
      (SendMR chDst, RecvMR chans) -> do
          let chB = map snd chans
          liftP $ forM_ chDst $ \ch -> sendChan ch chB
          sendACP $ ReqConnect childA childB [chN | (chN,_) <- chans]
      -- IMPOSSIBLE
      --
      -- GHC cannot understand that pattern match is exhaustive
      _ -> error "Impossible: pattern match is not exhaustive"



----------------------------------------------------------------
-- Promises
----------------------------------------------------------------