Skip to content

Commit 13487b6

Browse files
committed
Doc: Add translation
1 parent 8d5102f commit 13487b6

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

doc/translation.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Translation
2+
3+
We write ⟦`e`⟧Ξ to denote the translation of Simphony expression `e` using environment Ξ from A.
4+
5+
The translation produces a Simplicity expression with source type A.
6+
7+
The target type depends on the Simphony expression `e`.
8+
9+
## Unit literal
10+
11+
`()`⟧Ξ = unit: A → 𝟙
12+
13+
## Product constructor
14+
15+
If Ctx(Ξ) ⊩ `b`: B
16+
17+
If Ctx(Ξ) ⊩ `c`: C
18+
19+
Then ⟦`(b, c)`⟧Ξ = pair ⟦`b`⟧Ξ ⟦`c`⟧Ξ: A → B × C
20+
21+
## Left constructor
22+
23+
If Ctx(Ξ) ⊩ `b`: B
24+
25+
Then ⟦`Left(b)`⟧Ξ = injl ⟦`b`⟧Ξ: A → B + C
26+
27+
For any C
28+
29+
## Right constructor
30+
31+
If Ctx(Ξ) ⊩ `c`: C
32+
33+
Then ⟦`Right(c)`⟧Ξ = injr ⟦`c`⟧Ξ: A → B + C
34+
35+
For any B
36+
37+
## Bit string literal
38+
39+
If `s` is a bit string of 2^n bits
40+
41+
Then ⟦`0bs`⟧Ξ = const 0bs: A → 𝟚^(2^n)
42+
43+
## Byte string literal
44+
45+
If `s` is a hex string of 2^n digits
46+
47+
Then ⟦`0xs`⟧Ξ = const 0xs: A → 𝟚^(4 * 2^n)
48+
49+
## Variable
50+
51+
If Ctx(Ξ)(`v`) = B
52+
53+
Then ⟦`v`⟧Ξ = Ξ(`v`): A → B
54+
55+
## Witness value
56+
57+
Ctx(Ξ) ⊩ `witness(name)`: B
58+
59+
Then ⟦`witness(name)`⟧Ξ = witness: A → B
60+
61+
## Jet
62+
63+
If `j` is the name of a jet of type B → C
64+
65+
If Ctx(Ξ) ⊩ `b`: B
66+
67+
Then ⟦`jet_j b`⟧Ξ = comp ⟦`b`⟧Ξ jet_j: A → C
68+
69+
## Chaining
70+
71+
If Ctx(Ξ) ⊩ `b`: 𝟙
72+
73+
If Ctx(Ξ) ⊩ `c`: C
74+
75+
Then ⟦`b; c`⟧Ξ = comp (pair ⟦`b`⟧Ξ ⟦`c`⟧Ξ) (drop iden): A → C
76+
77+
## Let statement
78+
79+
If Ctx(Ξ) ⊩ `b`: B
80+
81+
If Product(PEnv(B, `p`), Ξ) ⊩ c: C
82+
83+
Then ⟦`let p: B = b; c`⟧Ξ = comp (pair ⟦`b`⟧Ξ iden) ⟦`c`⟧Product(PEnv(B, `p`), Ξ): A → C
84+
85+
## Match statement
86+
87+
If Ctx(Ξ) ⊩ `a`: B + C
88+
89+
If Product(PEnv(B, `x`), Ξ) ⊩ `b`: D
90+
91+
If Product(PEnv(C, `y`), Ξ) ⊩ `c`: D
92+
93+
Then ⟦`match a { Left(x) => a, Right(y) => b, }`⟧Ξ = comp (pair ⟦a⟧Ξ iden) (case ⟦b⟧Product(PEnv(B, `x`), Ξ) ⟦c⟧Product(PEnv(C, `y`), Ξ)): A → D
94+
95+
## Left unwrap
96+
97+
If Ctx(Ξ) ⊩ `b`: B + C
98+
99+
Then ⟦`b.unwrap_left()`⟧Ξ = comp (pair ⟦`b`⟧Ξ unit) (assertl iden #{fail 0}): A → B
100+
101+
## Right unwrap
102+
103+
If Ctx(Ξ) ⊩ `c`: B + C
104+
105+
Then ⟦`c.unwrap_right()`⟧Ξ = comp (pair ⟦`c`⟧Ξ unit) (assertr #{fail 0} iden): A → C

0 commit comments

Comments
 (0)