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 (x:int) : string =
match x with
| 0 -> "true"
| _ -> "false";;
print_string (is_zero 0);;
이렇게 수정하기
'Computer Science > 프로그래밍언어' 카테고리의 다른 글
OCaml Tutorial | Recursion with Lists (0) | 2022.03.08 |
---|---|
OCaml Tutorial | Introduction to Lists (0) | 2022.03.08 |
OCaml Tutorial | Introduction to Functions (0) | 2022.03.08 |
OCaml Tutorial | Introduction to Variables (0) | 2022.03.08 |
OCaml Tutorial | Conditional Statements (0) | 2022.03.08 |