LIGO-258 Docs updates

This commit is contained in:
Matej Šima 2020-01-29 16:15:03 +00:00 committed by Christian Rinderknecht
parent 04381b9dcf
commit 518c743172
8 changed files with 47 additions and 40 deletions

View File

@ -220,7 +220,7 @@ In our case, we have a `counter.ligo` contract that accepts a parameter of type
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```pascaligo
```pascaligo skip
// counter.ligo
type action is
| Increment of int

View File

@ -139,21 +139,8 @@ Conditional logic is an important part of every real world program.
```pascaligo group=e
const min_age: nat = 16n;
(*
This function is really obnoxious, but it showcases
how the if statement and it's syntax can be used.
Normally, you'd use `with (age > min_age)` instead.
*)
function is_adult(const age: nat): bool is
block {
var is_adult: bool := False;
if (age > min_age) then begin
is_adult := True;
end else begin
is_adult := False;
end
} with is_adult
if (age > min_age) then True else False
```
> You can run the function above with

View File

@ -200,6 +200,18 @@ const a: int = int(1n);
const b: nat = abs(1);
```
<!--END_DOCUSAURUS_CODE_TABS-->
## Check if a value is a `nat`
You can check if a value is a `nat`, by using a syntax specific built-in function, which accepts an `int` and returns an `option(nat)`, more specifically `Some(nat)` if the provided integer is a natural number, and `None` otherwise:
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```pascaligo
const its_a_nat: option(nat) = is_nat(1)
```
<!--ReasonLIGO-->
```reasonligo group=e
let a: int = int(1n);

View File

@ -0,0 +1,4 @@
const min_age: nat = 16n;
function is_adult(const age: nat): bool is
if (age > min_age) then True else False

View File

@ -0,0 +1 @@
const its_a_nat: option(nat) = is_nat(1)

View File

@ -0,0 +1,4 @@
type int_map is map(int, int);
function get_first(const int_map: int_map): option(int) is int_map[1]
// empty map needs a type annotation
const first: option(int) = get_first(((map end) : int_map ));

View File

@ -3,7 +3,7 @@ id: types
title: Types
---
LIGO is strongly and statically typed. This means that the compiler checks your program at compilation time and makes sure there won't be any type related runtime errors. LIGO types are built on top of Michelson's type system.
LIGO is strongly and statically typed. This means that the compiler checks your program at compilation time and makes sure there won't be any type related runtime errors. LIGO types are built on top of Michelson's type system.
## Built-in types
@ -36,6 +36,8 @@ let dog_breed: animal_breed = "Saluki";
<!--END_DOCUSAURUS_CODE_TABS-->
> Types in LIGO are `structural`, which means that `animalBreed`/`animal_breed` and `string` are interchangable and are considered equal.
## Simple types
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
@ -146,3 +148,18 @@ let ledger: account_balances =
```
<!--END_DOCUSAURUS_CODE_TABS-->
## Annotations
In certain cases, type of an expression cannot be properly determined. This can be circumvented by annotating an expression with it's desired type, here's an example:
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```pascaligo
type int_map is map(int, int);
function get_first(const int_map: int_map): option(int) is int_map[1]
// empty map needs a type annotation
const first: option(int) = get_first(((map end) : int_map ));
```
<!--END_DOCUSAURUS_CODE_TABS-->

View File

@ -5624,15 +5624,6 @@
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"dev": true
},
"klaw-sync": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz",
"integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.11"
}
},
"lazy-cache": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-2.0.2.tgz",
@ -7412,15 +7403,6 @@
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
"dev": true
},
"preprocess": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/preprocess/-/preprocess-3.1.0.tgz",
"integrity": "sha1-pE5c3Vu7WlTwrSiaru2AmV19k4o=",
"dev": true,
"requires": {
"xregexp": "3.1.0"
}
},
"prismjs": {
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.17.1.tgz",
@ -7750,6 +7732,12 @@
"picomatch": "^2.0.4"
}
},
"reason-highlightjs": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/reason-highlightjs/-/reason-highlightjs-0.2.1.tgz",
"integrity": "sha512-DWWPtfeQjwKgHj2OOieEIAB544uAVjwOAIAg2Yu09CobdUe41Yah0Z67GEvmVtpYCGG/+3CZvDRM1hMVr1zN3A==",
"dev": true
},
"rechoir": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
@ -9433,12 +9421,6 @@
"integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==",
"dev": true
},
"xregexp": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-3.1.0.tgz",
"integrity": "sha1-FNhGHgvdOCJL/uUDmgiY/EL80zY=",
"dev": true
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",