Reason
  • 문서
  • 해보기
  • API
  • 커뮤니티
  • 블로그
  • Languages icon한국어
    • 日本語
    • English
    • Deutsch
    • Español
    • Français
    • Português (Brasil)
    • Русский
    • Українська
    • 中文
    • 繁體中文
    • 번역 돕기
  • GitHub

›언어 기본

소개

  • What & Why

Setup

  • 설치
  • 에디터 플러그인

언어 기본

  • 개요
  • Let 바인딩
  • 원시 타입
  • 기본 자료구조
  • 타입
  • 레코드
  • Variant
  • Options and nullability
  • 함수
  • 재귀
  • 비구조화
  • 패턴 매칭
  • Mutable Bindings
  • 반복문
  • Modules

Advanced Features

  • JSX
  • 외부 접근
  • 예외
  • 오브젝트

JavaScript

  • 연동
  • 문법 치트시트
  • Pipe First
  • 프라미스
  • 라이브러리
  • JS에서 변환

추가 사항

  • 자주 물어보는 질문
  • 추가적으로 매력적인 것들
Translate

원시 타입

Quick overview: Primitives

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

Strings

Quick overview: Strings

Create a string using double quotes:

let s = "Hello World!";

Concatenate strings using the ++ operator:

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" */

문자

홑따옴표로 문자를 만들 수 있습니다:

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" */

정수

Quick overview: Numbers

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;

비트 연산자

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
};

부동 소수점

Quick overview: Numbers

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;

부울

Quick overview: Boolean

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 바인딩기본 자료구조 →
  • Strings
    • 문자
  • 정수
    • Integer literals
    • 비트 연산자
  • 부동 소수점
  • 부울