我对 CSP 的非常有限的理解是 CSP 运算符对应于以下 Haskell 类型:
-- Prefixing corresponds to functions
x :: A
P :: B
x -> P :: A -> C
-- Choice corresponds to product
P :: A
Q :: B
P □ Q :: (A, B)
-- Non-determinism corresponds to sum
-- I don't know how to make the non-determinism symbol, so I use (△)
P :: A
Q :: B
(P △ B) :: Either A B
然后,您可以使用代数同构来减少 CSP 表达式。使用维基百科示例:
(coin -> STOP) □ (card -> STOP)
-- translates to the following Haskell type:
(coin -> Stop, card Stop)
-- which is algebraically isomorphic to:
(Either coin card -> Stop)
-- translates in reverse back to CSP:
coin □ card -> STOP
另外,我认为维基百科的一个例子是错误的(或者我错了)。我相信这个表达式应该简化为:
(a -> a -> STOP) □ (a -> b -> STOP)
-- translates to the following Haskell type:
(a -> a -> STOP, a -> b -> STOP)
-- which is algebraically isomorphic to:
a -> Either a b -> STOP
-- translates in reverse back to CSP:
a -> (a △ b) -> STOP
不过,我还没有弄清楚接口并行的等价物。它似乎不符合一个优雅的概念。