|
1 | 1 | # 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 | +at ∈ Atomic type ::= integer |
| 9 | + | bytestring |
| 10 | + | string |
| 11 | + | bool |
| 12 | + | unit |
| 13 | + | data |
| 14 | + | 𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟷_𝚎𝚕𝚎𝚖𝚎𝚗𝚝 |
| 15 | + | 𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝙶𝟸_𝚎𝚕𝚎𝚖𝚎𝚗𝚝 |
| 16 | + | 𝚋𝚕𝚜𝟷𝟸_𝟹𝟾𝟷_𝚖𝚕𝚛𝚎𝚜𝚞𝚕𝚝 |
| 17 | +
|
| 18 | +T ∈ Built-in type ::= at |
| 19 | + | list(T) |
| 20 | + | pair(T, T) |
| 21 | +``` |
| 22 | + |
| 23 | +The following table shows the denotations and concrete syntaxes of the types and type operators: |
| 24 | + |
| 25 | +|Type 𝑇|Denotation |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 | + |
| 34 | +In the following, we use `𝑐(𝑇) ∈ 𝐂(𝑇)` to denote a valid representation of a constant of type 𝑇. |
| 35 | + |
| 36 | +### Concrete Syntax for Strings |
| 37 | + |
| 38 | +Strings are represented as sequences of Unicode characters enclosed in |
| 39 | +double quotes, and may include standard escape sequences. |
| 40 | +Surrogate characters in the range `U+D800` - `U+DFFF` are replaced with the Unicode replacement character `U+FFFD`. |
| 41 | + |
| 42 | +### Concrete Syntax for Lists and Pairs |
| 43 | + |
| 44 | +A list of type `list(𝑡)` is written as a syntactic list `[𝑐₁, … ,𝑐ₙ]`, where each `𝑐ᵢ ∈ 𝐂(𝑡)`. |
| 45 | + |
| 46 | +A pair of type `pair(𝑡₁, 𝑡₂)` is written as a syntactic pair `(𝑐₁, 𝑐₂)` where `𝑐₁ ∈ 𝐂(𝑡₁)` and `𝑐2 ∈ 𝐂(𝑡₂)`. |
| 47 | + |
| 48 | +Some valid constant expressions are: |
| 49 | +- `(con (list integer) [11, 22, 33])` |
| 50 | +- `(con (pair bool string) (True, "Plutus"))` |
| 51 | +- `(con (list (pair bool (list bytestring))) [(True, []), (False, [#,#1F]), (True, [#123456, #AB, #ef2804])])` |
| 52 | + |
| 53 | +### The `data` Type |
| 54 | + |
| 55 | +We provide a built-in type, `data`, which permits the encoding of simple data structures |
| 56 | +for use as arguments to Plutus Core scripts. |
| 57 | +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). |
| 58 | + |
| 59 | +### Concrete Syntax for `data` |
| 60 | + |
| 61 | +The concrete syntax for 𝚍𝚊𝚝𝚊 is given by |
| 62 | + |
| 63 | +```text |
| 64 | +𝑐(𝚍𝚊𝚝𝚊) ∶∶= (Constr 𝑐(𝚒𝚗𝚝𝚎𝚐𝚎𝚛) 𝑐(𝚕𝚒𝚜𝚝(𝚍𝚊𝚝𝚊))) |
| 65 | + | (Map 𝑐(𝚕𝚒𝚜𝚝(𝚙𝚊𝚒𝚛(𝚍𝚊𝚝𝚊,𝚍𝚊𝚝𝚊)))) |
| 66 | + | (List 𝑐(𝚕𝚒𝚜𝚝(𝚍𝚊𝚝𝚊))) |
| 67 | + | (I 𝑐(𝚒𝚗𝚝𝚎𝚐𝚎𝚛)) |
| 68 | + | (B 𝑐(𝚋𝚢𝚝𝚎𝚜𝚝𝚛𝚒𝚗𝚐)). |
| 69 | +``` |
| 70 | + |
| 71 | +Some valid data constants are: |
| 72 | +- `(con data (Constr 1 [(I 2), (B #), (Map [])]))` |
| 73 | +- `(con data (Map [((I 0), (B #00)), ((I 1), (B #0F))]))` |
| 74 | +- `(con data (List [(I 0), (I 1), (B #7FFF), (List []])))` |
| 75 | +- `(con data (I -22))` |
| 76 | +- `(con data (B #001A))` |
| 77 | + |
| 78 | +## Built-in Functions |
0 commit comments