“该值不是函数,无法应用。” F# 中的错误

发布于 2024-12-01 03:34:03 字数 1015 浏览 3 评论 0原文

我试图运行以下 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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

゛时过境迁 2024-12-08 03:34:03

没有人能猜出这里的答案。问题在于我决定从帖子中排除的其他内容:我的文件的标题:

#if INTERACTIVE
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";
#endif

;; 替换 ; 将使所有错误消失:

#if INTERACTIVE
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";;
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";;
#endif

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:

#if INTERACTIVE
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";
#endif

Replacing the ; by ;; will make all errors disappear:

#if INTERACTIVE
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";;
    #r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";;
#endif
多像笑话 2024-12-08 03:34:03

红色下划线清楚地表明编译器认为 pipe2 正在接受四个参数 - 您应该能够通过在整个测试表达式周围添加括号来确认这一点,如下所示: (test ns "namespace abs { def ghi })

但我不确定为什么;尝试在 pipeline2 调用周围加上括号:

let ns = 
  (pipe2  
     (spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter) 
     (spaces >>. skipString "{" >>. classes .>> skipString "}") 
     (fun name classes -> { Name = name; Classes = classes } ))

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:

let ns = 
  (pipe2  
     (spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter) 
     (spaces >>. skipString "{" >>. classes .>> skipString "}") 
     (fun name classes -> { Name = name; Classes = classes } ))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文