Skip to content

Commit

Permalink
Info about the unit type (#401)
Browse files Browse the repository at this point in the history
* Info about the unit type

* Move unit to complex types

* Add note on where to get all types for languages

* Clarify

* Examples of the unit type

* Don't define unit as a case of option
  • Loading branch information
timothymcmackin authored Jun 17, 2024
1 parent 3ba9b7d commit 3b5f48f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
36 changes: 35 additions & 1 deletion docs/smart-contracts/data-types/complex-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Complex data types
authors: 'Mathias Hiron (Nomadic Labs), Sasha Aldrick (TriliTech), Tim McMackin (TriliTech)'
last_update:
date: 5 October 2023
date: 17 June 2024
---

Tezos contracts support these complex data types.
Expand All @@ -17,6 +17,15 @@ The high-level languages may implement these data types slightly differently, bu
- [Variants and Unions](#variants)
- [Lambdas](#lambdas)
- [Tickets](#tickets)
- [Unit](#unit)

This list is intended for general information for developers and is not intended to be comprehensive.
For a complete list of data types that are available, see the reference information for the language that you are using:

- Michelson: [Types](https://tezos.gitlab.io/michelson-reference/#types)
- LIGO: [Introduction](https://ligolang.org/docs/intro/introduction?lang=jsligo)
- Archetype: [Types](https://archetype-lang.org/docs/reference/types)
- SmartPy: [Overview](https://smartpy.io/manual/syntax/overview)

## Pairs {#pairs}

Expand Down Expand Up @@ -456,3 +465,28 @@ Contracts can run these operations on tickets:
- LIGO: [Tickets](https://ligolang.org/docs/reference/current-reference#tickets)
- Archetype: [create_ticket and related](https://archetype-lang.org/docs/reference/expressions/builtins/#create_ticket%28s%20:%20T,%20n%20:%20nat%29)
- SmartPy: [Tickets](https://smartpy.io/manual/syntax/tickets)

## Unit {#unit}

In Tezos, the `unit` type contains a single value that holds no information.
Smart contracts use unit values as placeholders where a variable is required but no other information is needed.
It is the input type of functions taking no input, the output type of functions producing no output, and the storage type of contracts storing no information.

For example, if a LIGO entrypoint receives no parameter, the data type of the entrypoint's parameter is `unit`:

```jsligo
@entry
const myentrypoint = (_unusedParameter: unit, store: storageType): returnType => {
// ...
}
```

Similarly, if you call this entrypoint with the Octez client and omit the `--arg` argument to pass no parameter, the client passes unit in the background.

Unit is a concept that Tezos inherits from OCaml; see [Side-Effects and the unit Type](https://ocaml.org/docs/tour-of-ocaml#side-effects-and-the-unit-type) in the OCaml documentation.

### Implementation details

- LIGO: [Unit](https://ligolang.org/docs/variants/unit/?lang=jsligo)
- Archetype: [Unit](https://archetype-lang.org/docs/reference/types/#unit)
- SmartPy: [Unit](https://smartpy.io/manual/syntax/unit)
10 changes: 9 additions & 1 deletion docs/smart-contracts/data-types/primitive-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Primitive data types
authors: 'Mathias Hiron (Nomadic Labs), Sasha Aldrick (TriliTech), Tim McMackin (TriliTech)'
last_update:
date: 4 October 2023
date: 4 June 2024
---

Tezos contracts support these primitive data types.
Expand All @@ -16,6 +16,14 @@ The high-level languages may implement these data types slightly differently, bu
- [Timestamps](#timestamps)
- [Addresses](#addresses)

This list is intended for general information for developers and is not intended to be comprehensive.
For a complete list of data types that are available, see the reference information for the language that you are using:

- Michelson: [Types](https://tezos.gitlab.io/michelson-reference/#types)
- LIGO: [Introduction](https://ligolang.org/docs/intro/introduction?lang=jsligo)
- Archetype: [Types](https://archetype-lang.org/docs/reference/types)
- SmartPy: [Overview](https://smartpy.io/manual/syntax/overview)

## Numeric data types: `int` and `nat` {#numeric}

Integers (`int`) are whole numbers that can be positive or negative.
Expand Down

0 comments on commit 3b5f48f

Please sign in to comment.