在ocaml中搜索列表中的元素
我得到一个错误:在ocaml中搜索列表中的元素,ocaml,Ocaml,我得到一个错误: (* function for union of two ordered sets*) let rec search n list1 = match list1 with [] -> false | head :: tail when head = n -> true | head :: tail when head != n -> search n tail ;; (* function calls and output *) Pr
(* function for union of two ordered sets*)
let rec search n list1 = match list1 with
[] -> false
| head :: tail when head = n -> true
| head :: tail when head != n -> search n tail
;;
(* function calls and output *)
Printf.printf("\nList = {");;
open Printf
let list1=[3;1;2;4];; (* Input first set here *)
let () = List.iter (printf " %d ") list1;;
printf("}");;
n=2;;
let u = search n list1;;
第15行=>“n=2;;”
请告知这是否是一个语法错误或其他,以及可能的补救措施。实现是在linux上完成的。在OCaml中,要使用名称绑定值,应该使用
len name=value
语法表达式n=2
将n
与2
进行比较,但是n
尚未定义,因此会出现错误。您应该使用让n=2
将值绑定到名称
File "search.ml", line 15, characters 0-1:
Error: Unbound value n