“该值不是函数,无法应用。” F# 中的错误
我试图运行以下 FParsec
代码,直到由于某种原因它停止工作:
我得到的错误是,
"The value is not a function and cannot be applied."
如果我注释掉最后一行代码(test ns ".."
),它不会产生错误。关于如何解决这个问题有什么想法吗?
文本形式的源代码如下:
open System
open FParsec
let test p str =
match run p str with
| Success(result, _, _) -> printfn "Success: %A" result
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg
type Namespace = { Name : string; Classes : string list; }
let classes : Parser<string list, unit> =
many (spaces >>. many1Satisfy isLetter .>> spaces)
let ns =
pipe2
(spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter)
(spaces >>. skipString "{" >>. classes .>> skipString "}")
(fun name classes -> { Name = name; Classes = classes } )
test ns "namespace abc { def ghi }"
I was trying to run the following FParsec
code, until by some reason it stopped working:
The error I am getting is
"The value is not a function and cannot be applied."
If I comment out the last line of code (test ns ".."
) it will not yield an error, though. Any thoughts on how to solve this?
The source code in text form is the following:
open System
open FParsec
let test p str =
match run p str with
| Success(result, _, _) -> printfn "Success: %A" result
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg
type Namespace = { Name : string; Classes : string list; }
let classes : Parser<string list, unit> =
many (spaces >>. many1Satisfy isLetter .>> spaces)
let ns =
pipe2
(spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter)
(spaces >>. skipString "{" >>. classes .>> skipString "}")
(fun name classes -> { Name = name; Classes = classes } )
test ns "namespace abc { def ghi }"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有人能猜出这里的答案。问题在于我决定从帖子中排除的其他内容:我的文件的标题:
用
;;
替换;
将使所有错误消失:Noone could have guessed the answer here. The problem lied with other thing that I had decided to exclude from the post: the very header of my file:
Replacing the
;
by;;
will make all errors disappear:红色下划线清楚地表明编译器认为
pipe2
正在接受四个参数 - 您应该能够通过在整个测试表达式周围添加括号来确认这一点,如下所示:(test ns "namespace abs { def ghi })
但我不确定为什么;尝试在 pipeline2 调用周围加上括号:
The red underlines clearly show that the compiler thinks that
pipe2
is taking four arguments--you should be able to confirm this by added parentheses around the entire test expression like so:(test ns "namespace abs { def ghi })
I'm not sure why though; try putting parentheses around the pipe2 call: