Computer Science 387

OCaml 함수 예제

알아야 하는 것 for문 함수 구조 타입 리스트 인덱싱 match with OCaml version 4.08.1 # let rec last = function | [] -> None | [x] -> Some x | _::t -> last t;; val last : 'a list -> 'a option = # last ["a";"b";"c";"d"];; - : string option = Some "d" # last [];; - : 'a option = None # # let rec last_two = function | [] | [_] -> None | [x;y] -> Some (x,y) | _::t -> last_two t;; val last_two : 'a list -> ('a * 'a) option..

OCaml Tutorial | Introduction to Lists

OCaml version 4.08.1 # [1;2;3];; - : int list = [1; 2; 3] # [];; - : 'a list = [] # [1];; - : int list = [1] # ["hi";"j ^CInterrupted. # ["hi ^CInterrupted. # ["a";"b";"c"];; - : string list = ["a"; "b"; "c"] # [1.2;3.2];; - : float list = [1.2; 3.2] # 선언은 이렇게 # let x : int list = [2;3;4];; val x : int list = [2; 3; 4] # let x = [2;3;4];; val x : int list = [2; 3; 4] let y = [1;2;3];; let is_lis..

OCaml Tutorial | Introduction to Pattern Matching

let is_zero (x:int) : string = match x with | 0 -> "true" | 1 -> "false";; print_string (is_zero 0);; c언어의 case랑 비슷한 기능인 것 같음 @martini:~$ ocaml pattern.ml File "./pattern.ml", line 2, characters 8-81: 2 | ........match x with 3 | | 0 -> "true" 4 | | 1 -> "false".. Warning 8: this pattern-matching is not exhaustive. Here is an example of a case that is not matched: 2 true 이 에러 해결하려면, let is_zero ..

노마드 코더 ReactJS | #3 State

#3.0 Understanding State React.js의 state : 데이터가 저장되는 곳 예시를 전체 구현하려면, state를 이용해주어야 한다. JSX React Element를 함수 안에 넣으면, 원하는 만큼 사용할 수 있다. 재활용 가능함. 함수라서 ㄷㄷ - 최고는 아닌 FM 방식 리액트에서는 중괄호를 열고 변수 이름을 넣어주면 된다. 변수들을 연결해줄 수 있음 => React.js는 바뀐 부분만 업데이트해준다. => 인터렉티브한 어플리케이션을 만들기 좋은 특성 #3.1 setState part one - 중괄호로 변수 연결해줄 수 있다. - ui 업데이트 하고 싶으면, render를 해주면 됨 - 랜더링하더라도 바뀐 부분만 새로 생성해주어서 인터렉티브한 어플리케이션을 개발하기 좋음- 데이..