Aleo
September 7, 2022

Leo: Data Types and Values

Welcome to the new article dedicated to the Leo programming language for the Aleo privacy platform.

In this article, we will touch upon information about data types in detail, this is very important, since all apks are tied specifically to this. In principle, it is impossible to imagine any application in any programming language without this. Introduction from prehistory.

Leo is a statically typed language, which means that we must know the type of each variable before executing the schema.

How it looks like in non-typed languages, for example in JavaScript: let person = 'Ivan', where let is the declaration of a variable, person is the name of the variable, 'Ivan' is the value of the variable. But in typed programming languages, after the declaration and before the value of a variable, its type is specified. For example, that in our example it will be a string, in most languages, it is a string or str.

Well, let's get down to the Leo language. There are no such values ​​as undefined or null in Leo. For example, in the same JS there are such data types, but in the case of the Leo language, when assigning a new variable, the value type must be explicitly specified.

Variables in Leo are always passed by value, which means they are always copied when used as function input or in assignments.

Leo supports standard true or false boolean values. This requires an explicit bool type for booleans in statements.

let c: bool = false;

That is, in the example above, we declared a variable called c with let, after which we set it to a boolean type - bool and its value - false.

Leo also supports signed integers.i8, i16, i32, i64, i128 And unsigned integers u8, u16, u32, u64, u128.

let с: u8 = 1u8;
Integers with a higher bit length create more constraints in the circuit, which can slow down computation time.

I also want to note that Leo does not support type ghosts, so the programming language will not use the integer type by default. The definition must include an explicit type.

let с: u8 = 2u8; // explicit type, everything is ok
let v: u8 = 2; // implicit type, will not work

Leo supports the field type of the field's own elements as unsigned numbers up to the length of the field's modulus.

let c: field = 1field;
let v: field = 2188824287183927522224640574525727503698;

Leo also supports groups, which is a bit of a non-standard data type. A set of affine points on an elliptic curve is passed to the compiler and forms a group. Leo supports this set as a primitive data type. The elements of a group are special because their values can be determined from the x-coordinate of a pair of coordinates. For example: 1group. The group type keyword - group must be used when specifying the group coordinate.

let c: group = 0group; // group zero
let v: group = 1group; // group generator
let b: group = 2group; // 2 * group generator

Leo supports the scalar type for field elements in a scalar field.

let c: scalar = 1scalar;

Also in Leo there is such a data type as address, which I think is not surprising. Addresses are defined to include compiler-optimized subroutines for parsing and working with addresses. These semantics will be followed by the standard library in a future sprint.

function main(owner: address) {
let receiver: address = aleo1ezamst4pjgj9zfxqq0fwfj8a4cjuqndmasgata3hggzqygggnyfq6kmyd4;
}

As a result, I can highlight the fact that the Leo programming language contains both standard data types and non-standard ones for the layman in programming. But all this information looks quite interesting, we can clearly see what the code looks like under the hood and what it consists of and what logic the work is going on. Personally, I was interested in the function that we saw at the end of this article, which takes the sender's address, and the recipient's address is declared in the function itself, yes it's not finished, but the syntax is pretty cool, isn't it?