【发布时间】:2016-08-15 02:13:25
【问题描述】:
这个Parse error: "in" expected after [binding] (in [expr])
是我在Ocaml 用户中搜索到的常见错误,但是在我看到的示例中我没有找到错误的答案,那么我将解释我的问题:
我声明了这个函数:
let rec unit_propag xs =
let cuAux = teste xs
let updatelist = funfilter (List.hd(List.hd cuAux)) (xs)
let updatelist2 = filtraelem (negar(List.hd(List.hd cuAux))) (updatelist)
if(not(List.mem [] xs) && (teste xs <> []))
then
unit_propag updatelist2
;;
我在这段代码中使用的函数之前是这样声明的:
let funfilter elem xs = List.filter (fun inner -> not (List.mem elem inner)) xs;;
let filtraele elem l = List.map( fun y -> List.filter (fun x -> x <> elem) y)l;;
let teste xs = List.filter(fun inner ->(is_single inner)inner)xs;;
let is_single xs = function
|[_] -> true
|_ -> false
;;
let negar l =
match l with
V x -> N x
|N x -> V x
|B -> T
|T -> B
;;
但不是按照这个顺序。
好吧,他们都在做我想做的事,但是现在当我声明 unit_propag 并尝试编译时,我在
let cuAux = teste xs
它说:
File "exc.ml", line 251, characters 20-22:
Parse error: "in" expected after [binding] (in [expr])
Error while running external preprocessor
Command line: camlp4o 'exc.ml' > /tmp/ocamlpp5a7c3d
然后我尝试在每个函数的末尾添加;,然后我的"in"错误出现在最后一个函数的行,是本案unit_propag updatelist2
我做错了什么?人们通常说这种错误发生在那个代码之前,但是当我评论这个函数时,程序编译完美。
我需要发布更多我的代码吗?或者我需要更清楚地回答我的问题?
在Ocaml 中是否可以做到这一点,或者我正在做一些我做不到的事情?
谢谢
【问题讨论】:
-
使用适当的自动缩进工具,如 ocaml-mode、tuareg-mode 或 ocp-indent 可以轻松避免此类问题。如果自动缩进结果与您认为的不同,则很可能是您在附近的某个地方犯了语法错误。
-
我现在正在使用自动缩进程序 thnx 作为提示
标签: list function multidimensional-array ocaml