Skip to content

Commit 02ca597

Browse files
authored
Merge pull request #38 from cardano-scaling/zliu41/builtin
Plutus built-in types
2 parents 8317300 + c6892e4 commit 02ca597

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

src/plutus/builtin.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,93 @@
11
# Built-in Types and Functions
2+
3+
## Built-in Types
4+
5+
The listing below defines the built-in types in UPLC.
6+
7+
```text
8+
a ∈ Atomic type ::= integer
9+
| bytestring
10+
| string
11+
| bool
12+
| unit
13+
| data
14+
| 𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟷_𝚎𝚕𝚎𝚖𝚎𝚗𝚝
15+
| 𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟸_𝚎𝚕𝚎𝚖𝚎𝚗𝚝
16+
| 𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝚖𝚕𝚛𝚎𝚜𝚞𝚕𝚝
17+
18+
T ∈ Built-in type ::= a
19+
| list(T)
20+
| pair(T, T)
21+
```
22+
23+
The following table shows the values and concrete syntaxes of the types and type operators:
24+
25+
|Type 𝑇|Value |Concrete Syntax 𝐂(𝑇) |
26+
|:--|:-----------------|:-----------------|
27+
|integer | `` | `-?[0-9]+` |
28+
|bytestring| the set of sequences of bytes or 8-bit characters | `#([0-9A-Fa-f][0-9A-Fa-f])*` |
29+
|string | the set of sequences of Unicode characters | see below |
30+
|bool | `{true, false}` | `True \| False` |
31+
|unit | `{()}` | `()` |
32+
|data | see below | see below |
33+
|𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟷_𝚎𝚕𝚎𝚖𝚎𝚗𝚝| `𝐺₁` | `0x[0-9A-Fa-f]{96}` (see below) |
34+
|𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟸_𝚎𝚕𝚎𝚖𝚎𝚗𝚝| `𝐺₂` | `0x[0-9A-Fa-f]{192}` (see below) |
35+
|𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝚖𝚕𝚛𝚎𝚜𝚞𝚕𝚝| `𝐻` | see below |
36+
37+
For the definitions of `𝐺₁`, `𝐺₂` and `𝐻`, refer to the Plutus Core Spec
38+
39+
In the following, we use `𝑐(𝑇) ∈ 𝐂(𝑇)` to denote a valid representation of a constant of type 𝑇.
40+
41+
### Concrete Syntax for Strings
42+
43+
Strings are represented as sequences of Unicode characters enclosed in
44+
double quotes, and may include standard escape sequences.
45+
Surrogate characters in the range `U+D800` - `U+DFFF` are replaced with the Unicode replacement character `U+FFFD`.
46+
47+
### Concrete Syntax for Lists and Pairs
48+
49+
A list of type `list(𝑡)` is written as a syntactic list `[𝑐₁, … ,𝑐ₙ]`, where each `𝑐ᵢ ∈ 𝐂(𝑡)`.
50+
51+
A pair of type `pair(𝑡₁, 𝑡₂)` is written as a syntactic pair `(𝑐₁, 𝑐₂)` where `𝑐₁ ∈ 𝐂(𝑡₁)` and `𝑐₂ ∈ 𝐂(𝑡₂)`.
52+
53+
Some valid constant expressions are:
54+
- `(con (list integer) [11, 22, 33])`
55+
- `(con (pair bool string) (True, "Plutus"))`
56+
- `(con (list (pair bool (list bytestring))) [(True, []), (False, [#,#1F]), (True, [#123456, #AB, #ef2804])])`
57+
58+
### The `data` Type
59+
60+
We provide a built-in type, `data`, which permits the encoding of simple data structures
61+
for use as arguments to Plutus Core scripts.
62+
The Haskell definition of `data` can be found in [PlutusCore.Data](https://plutus.cardano.intersectmbo.org/haddock/latest/plutus-core/PlutusCore-Data.html#t:Data).
63+
64+
### Concrete Syntax for `data`
65+
66+
The concrete syntax for 𝚍𝚊𝚝𝚊 is given by
67+
68+
```text
69+
𝑐(𝚍𝚊𝚝𝚊) ∶∶= (Constr 𝑐(𝚒𝚗𝚝𝚎𝚐𝚎𝚛) 𝑐(𝚕𝚒𝚜𝚝(𝚍𝚊𝚝𝚊)))
70+
| (Map 𝑐(𝚕𝚒𝚜𝚝(𝚙𝚊𝚒𝚛(𝚍𝚊𝚝𝚊,𝚍𝚊𝚝𝚊))))
71+
| (List 𝑐(𝚕𝚒𝚜𝚝(𝚍𝚊𝚝𝚊)))
72+
| (I 𝑐(𝚒𝚗𝚝𝚎𝚐𝚎𝚛))
73+
| (B 𝑐(𝚋𝚢𝚝𝚎𝚜𝚝𝚛𝚒𝚗𝚐)).
74+
```
75+
76+
Some valid data constants are:
77+
- `(con data (Constr 1 [(I 2), (B #), (Map [])]))`
78+
- `(con data (Map [((I 0), (B #00)), ((I 1), (B #0F))]))`
79+
- `(con data (List [(I 0), (I 1), (B #7FFF), (List []])))`
80+
- `(con data (I -22))`
81+
- `(con data (B #001A))`
82+
83+
### Concrete syntax for BLS12-381 Types
84+
85+
The concrete syntaxes for `𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟷_𝚎𝚕𝚎𝚖𝚎𝚗𝚝` and `𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟸_𝚎𝚕𝚎𝚖𝚎𝚗𝚝` are provided only for use in textual Plutus Core programs, for example for experimentation and testing.
86+
We do not support constants of any of the BLS12-381 types in serialised programs.
87+
88+
If you need to put `𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟷_𝚎𝚕𝚎𝚖𝚎𝚗𝚝` and `𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟸_𝚎𝚕𝚎𝚖𝚎𝚗𝚝` in your script, you can instead use the appropriate uncompression function on a bytestring constant.
89+
90+
No concrete syntax is provided for values of type `𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝚖𝚕𝚛𝚎𝚜𝚞𝚕𝚝`.
91+
It is not possible to parse such values, and they will appear as `(con bls12_381_mlresult <opaque>)` if output by a program.
92+
93+
## Built-in Functions

src/plutus/syntax.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,4 @@ De Bruijn indices are used in serialized scripts.
5050
It therefore makes the most sense for a CEK machine implementation to use de Bruijn indices.
5151

5252
When using de Bruijn indices, the binder `𝑥` in `(lam 𝑥 𝑀)` is irrelevant, and any number can be used.
53-
54-
## The `data` Type
55-
56-
We provide a built-in type, `data`, which permits the encoding of simple data structures
57-
for use as arguments to Plutus Core scripts.
58-
The Haskell definition of `data` can be found in [PlutusCore.Data](https://plutus.cardano.intersectmbo.org/haddock/latest/plutus-core/PlutusCore-Data.html#t:Data).
53+
0 is a good choice since it is not a valid de Bruijn index.

0 commit comments

Comments
 (0)