Common Parse error: "in" in a function that call other functions OCaml
Common Parse error: "in" in a function that call other functions OCaml
这个 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
我做错了什么?人们通常说这种错误发生在该代码之前,但是当我注释这个函数时程序编译完美。
我需要 post 我的更多代码?或者我需要在我的问题中更清楚?
在 Ocaml
中可以这样做吗?或者我正在做我不能做的事情?
谢谢
错误消息说你缺少in
,所以通过添加;
来解决它似乎很奇怪:-)
无论如何,在函数 unit_propag
.
中的所有 let
个关键字之后,您还缺少关键字 in
你应该这样写:
let rec unit_propag xs =
let cuAux = teste xs in
let updatelist = funfilter (List.hd(List.hd cuAux)) (xs) in
let updatelist2 =
filtraelem (negar(List.hd(List.hd cuAux))) (updatelist)
in
if (not (List.mem [] xs) && (teste xs <> [])) then
unit_propag updatelist2
这里已经多次解释了基本问题(如您所见)。关键字 let
基本上有两种用法。在外层,它定义了模块中的值。在另一个定义中,它定义了一个局部变量并且 必须 后跟 in
。这三个let
在unit_propag
.
的定义里面
另一种解释 let
用法的尝试在这里:OCaml: Call function within another function。
这个 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
我做错了什么?人们通常说这种错误发生在该代码之前,但是当我注释这个函数时程序编译完美。
我需要 post 我的更多代码?或者我需要在我的问题中更清楚?
在 Ocaml
中可以这样做吗?或者我正在做我不能做的事情?
谢谢
错误消息说你缺少in
,所以通过添加;
来解决它似乎很奇怪:-)
无论如何,在函数 unit_propag
.
let
个关键字之后,您还缺少关键字 in
你应该这样写:
let rec unit_propag xs =
let cuAux = teste xs in
let updatelist = funfilter (List.hd(List.hd cuAux)) (xs) in
let updatelist2 =
filtraelem (negar(List.hd(List.hd cuAux))) (updatelist)
in
if (not (List.mem [] xs) && (teste xs <> [])) then
unit_propag updatelist2
这里已经多次解释了基本问题(如您所见)。关键字 let
基本上有两种用法。在外层,它定义了模块中的值。在另一个定义中,它定义了一个局部变量并且 必须 后跟 in
。这三个let
在unit_propag
.
另一种解释 let
用法的尝试在这里:OCaml: Call function within another function。