Hypha - Type Reconstruction for the Linear π-Calculus

Hypha is a prototype implementation of the type reconstruction algorithm described in Type Reconstruction for the Linear π-Calculus with Composite and Equi-Recursive Types. It is implemented in Haskell, comes with the full source code (see the download section below) and a bunch of examples.

History

Download

The source code of Hypha can be downloaded at the links below. You need GHC, Alex and Happy to compile the tool. The easiset way to get them all at once is to install the Haskell Platform. In addition, you must install the Haskell packages base-unicode-symbols, containers-unicode-symbols, and multiset. A Makefile is provided.

Example

Below are three processes that visit a binary tree where each node contains a channel: take sends a message on the channel found on any node that is reachable through an even number of right branches from the root of the tree; skip sends a message on the channel found on any node that is reachable through an odd number of right branches from the root of the tree; overall, all sends a message on every channel in the tree.

*all?t. { take!t | skip!t } | *take?t. case t of { Leaf ⇒ {} ; Node(c,l,r) ⇒ c!0 | take!l | skip!r } | *skip?t. case t of { Leaf ⇒ {} ; Node(c,l,r) ⇒ skip!l | take!r } | all!tree

The types inferred by Hypha reflect the behavior of the three processes:

all : {ω,1}[μα.(Leaf ⊕ Node {0,1}[Int] × α × α)] take : {ω,ω}[μα.(Leaf ⊕ Node {0,1}[Int] × α × μβ.(Leaf ⊕ Node {0,0}[Int] × β × α))] skip : {ω,ω}[μα.(Leaf ⊕ Node {0,0}[Int] × α × μβ.(Leaf ⊕ Node {0,1}[Int] × β × α))] tree : μα.(Leaf ⊕ Node {0,1}[Int] × α × α)

Syntax

Below is the EBNF grammar describing the syntax of processes accepted by Hypha. The symbols ⇒ ≤ ≥ ≠ × ∧ ∨ ¬ can also be entered as => <= >= <> * /\ \/ not respectively.

Process ::= Expression![Expression] [. Process] output
| Expression?[Pattern] [. Process] input
| let Pattern = Expression in Process local binding
| def Definition [and Definition]* in Process definitions
| case Expression of { Rule [; Rule]* } pattern matching
| if Expression then Process else Process conditional
| Process | Process parallel composition
| new var [: Type] in Process new channel
| { [Process] } group
| *Process replication
Definition ::= var?[Pattern] = Process persistent input
Rule ::= tag [Pattern]Process match
Pattern ::= () unit
| _ [: Type] anonymous
| var [: Type] variable
| Pattern as var [: Type] ascription
| Pattern, Pattern pair
| (Pattern) group
Expression ::= () unit
| n integer
| true boolean true
| false boolean false
| var variable
| unop Expression unary operator
| Expression binop Expression binary operator
| (Expression) group
Type ::= Unit | Bool | Int basic types
binop ::= ∧ | ∨ | < | > | ≤ | ≥ | = | ≠ | + | - | × | / | , binary operators
unop ::= tag | ¬ | fst | snd unary operators
var ::= [a-z] [a-z 0-9 _ ']* variable
tag ::= [A-Z] [a-z 0-9 _ ']* tag
n ::= [0-9]+ integer

References