Computer Science/프로그래밍언어

OCaml Tutorial | Introduction to Lists

토마토. 2022. 3. 8. 18:37

   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_list_empty (1:int list):int =
        begin match 1 with
        | [] -> 1
        | h::t -> 0
        end;;
print_int (is_list_empty y);;