, 목록이 일정하게 증가하는 경우 테스트 기능, 소스 코드가 및 케이스를 테스트하는 것입니다 :utop에서 패턴 일치가 더 엄격합니까?
open Printf
let rec mon_inc (numbers : int list) : bool =
match numbers with
| [] -> true
| _ :: [] -> true
| hdn :: tln -> (hdn <= (List.hd tln)) && mon_inc(tln)
let a = [1;2;5;5;8]
let b = [1;2;5;4;8]
let c = [8]
let d = []
let e = [7;8]
let() =
printf "The answer of [1;2;5;5;8]: %B\n" (mon_inc a)
let() =
printf "The answer of [1;2;5;4;8]: %B\n" (mon_inc b)
let() =
printf "The answer of [8]: %B\n" (mon_inc c)
let() =
printf "The answer of []: %B\n" (mon_inc d)
let() =
printf "The answer of [7;8]: %B\n" (mon_inc e)
컴파일하고 코드를 실행합니다, 그러나
$ corebuild inc.native
$ ./inc.native
The answer of [1;2;5;5;8]: true
The answer of [1;2;5;4;8]: false
The answer of [8]: true
The answer of []: true
The answer of [7;8]: true
을 때 이 함수를 utop에서 사용하려면 다음과 같이 표시하십시오.
utop # #use "inc.ml";;
File "inc.ml", line 7, characters 29-40:
Error: This expression has type int option
but an expression was expected of type int