Reason
  • Документация
  • Попробовать
  • API
  • Сообщество
  • Блог
  • Languages iconРусский
    • 日本語
    • English
    • Deutsch
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Українська
    • 中文
    • 繁體中文
    • Помочь с переводом
  • GitHub

›Основы языка

Введение

  • Что и зачем

Установка

  • Установка
  • Плагины для редакторов и IDE

Основы языка

  • Обзор
  • Let Bindings
  • Primitives
  • Basic Structures
  • Types
  • Records
  • Variants
  • Options and nullability
  • Functions
  • Recursion
  • Деструктуризация
  • Pattern Matching
  • Mutable Bindings
  • Loops
  • Modules

Advanced Features

  • JSX
  • External
  • Исключения
  • Объекты

JavaScript

  • Взаимодействие с JavaScript
  • Шпаргалка по синтаксису
  • Pipe First
  • Промис
  • Библиотеки
  • Конвертация из JS

Дополнительно

  • Часто задаваемые вопросы (FAQ)
  • Дополнительные инструменты
Translate

Primitives

Краткая информация: Базовые Типы

These are the built in types that can be used to represent information and build more complex types.

Строки

Краткая информация: Строки

Строки в Reason заключаются в двойные кавычки:

let s = "Hello World!";

Для объединения двух строк используется оператор ++:

let s = "Hello " ++ "World!";

More String functions can be found in standard libraries:

  • Native: module String
  • BuckleScript: module Js.String
let s = String.trim("  extra whitespace\n");
/* "extra whitespace" */

let s = String.concat("\n", ["line 1", "line 2"]);
/* "Line 1\nLine 2" */

let s = String.sub("Hello World!", 6, 5);
/* "World" */

Символ

Символ в Reason заключается в одинарные кавычки:

let c = 'a';

Access the char at an index using string.[index]:

let c = "Hello".[1];
/* 'e' */

Convert char to string:

let s = String.make(1, 'c');
/* "c" */

let charArray = [| 'H', 'e', 'l', 'l', 'o' |];
let s = String.init(5, i => charArray[i]);
/* "Hello" */

Целое Число

Краткая информация: Числа

Integers are whole numbers. Their bit-size depends on the platform.

let x = 23;
let x = -23;

Standard operations include +, -, *, /, mod:

let x = 23 + 1 - 7 * 2 / 5;
let x = 13 mod 2;

Integer literals

Different radix literals can be created using prefixes 0x, 0o, 0b:

let decimal = 11256099;
let hex = 0xABC123;
let octal = 0o52740443;
let binary = 0b101010111100000100100011;

Literals can be broken up using the _ character which will be ignored:

let trillion = 1_000_000_000_000;

Bitwise operations

Use infix functions: land, lor, lxor, lnot, lsl, lsr, asr from module Pervasives

let x = 0b1010 lor 0b1100;
/* 0b1110, 14 */

Many bit tricks can be found here: bithacks

let isPowerOfTwo = x => {
  x !== 0 && x land (x - 1) === 0
};

Число с плавающей запятой

Краткая информация: Числа

Floats are 64-bit numbers that may have a decimal. They follow the IEEE 754 standard.

let x = 23.0;
let x = 23.;
let x = -23.0;

Standard operations include +., -., *., /., **:

let x = 3.0 +. 1.0 -. 7.0 *. 2.0 /. 5.0;

/* Exponentiation */
let x = 2.0 ** 3.0;

Логический Тип

Краткая информация: Логический Тип

Reason supports a normal set of boolean and logical operations:

  • Boolean operations: !, &&, ||
  • Comparison: >, <, >=, <=
  • Reference equality: ===, !==
  • Structural equality: ==, !=
let x = true;
let y = !true;
let z = x && y || false;
← Let BindingsBasic Structures →
  • Строки
    • Символ
  • Целое Число
    • Integer literals
    • Bitwise operations
  • Число с плавающей запятой
  • Логический Тип