如何修复此 FS00003 错误?

发布于 2024-12-07 21:22:56 字数 1878 浏览 0 评论 0原文

这是我的代码:

module RTX

open System
open System.Text.RegularExpressions

let input = "Line 1: Num allocs:3 New:2 Delete:1
Line 2: Num allocs:3 New:2 Delete:1
Line 3: Num allocs:3 New:2 Delete:1"

type AllocResult = { lineNo:string; numAllocs:string; news:string; frees:string }

let matches = Regex.Matches(input,@"Line (\d+): Num allocs:(\d+) New:(\d+) Delete:(\d+)",RegexOptions.Singleline)
let matchCollection = [ for m in matches do if m.Success then yield [for l in m.Groups -> l.Value]]
let allocCreator (e: string list) = { lineNo = e.[0]; numAllocs = e.[1]; news = e.[2]; frees = e.[3] }
let wfirst = List.map allocCreator List.map List.tail matchCollection

List.iter (fun e -> printfn "%s\n") wfirst
//List.iter (printfn "%s\n") matchCollection
Console.ReadLine()

我收到的错误是:This value is not a function and can not be apply (FS0003),它出现在 List.map allocCreator 部分。基本上,我想从“匹配”中删除匹配的字符串,并仅将捕获保留在记录中。

编辑:我将尝试更多地解释我想要实现的目标。匹配结果将是这样的:

[ "Line 1: Num allocs:3 New:2 Delete:1"; "1"; "3"; "2"; "1"; ]

通过使用 let matchCollection = [ for m in matches do if m.Success then yield [for l in m.Groups ->; l.Value]] 我试图获取列表的列表,如下所示:

[["Line 1: Num allocs:3 New:2 Delete:1"; "1"; "3"; "2"; "1"; ];["Line 2: Num allocs:3 New:2 Delete:1";"2"; "3"; "2"; "1"; ]; ["Line 3: Num allocs:3 New:2 Delete:1";"3"; "3"; "2"; "1"]]

通过使用 List.map List.tail matchCollection,我试图从上面的列表中获取,对此:

[["1"; "3"; "2"; "1"; ];["2"; "3"; "2"; "1"; ]; [;"3"; "3"; "2"; "1"]]

通过使用List.map allocCreator,我试图将上面的列表转换为记录列表。我对 F# 有点陌生,我的逻辑可能是错误的,但我不明白为什么/在哪里。

编辑2:这似乎是一个优先级问题。如果我这样做:

let wfirst = List.map allocCreator (List.map List.tail matchCollection);;

那么我就会得到我需要的东西。

This is my code:

module RTX

open System
open System.Text.RegularExpressions

let input = "Line 1: Num allocs:3 New:2 Delete:1
Line 2: Num allocs:3 New:2 Delete:1
Line 3: Num allocs:3 New:2 Delete:1"

type AllocResult = { lineNo:string; numAllocs:string; news:string; frees:string }

let matches = Regex.Matches(input,@"Line (\d+): Num allocs:(\d+) New:(\d+) Delete:(\d+)",RegexOptions.Singleline)
let matchCollection = [ for m in matches do if m.Success then yield [for l in m.Groups -> l.Value]]
let allocCreator (e: string list) = { lineNo = e.[0]; numAllocs = e.[1]; news = e.[2]; frees = e.[3] }
let wfirst = List.map allocCreator List.map List.tail matchCollection

List.iter (fun e -> printfn "%s\n") wfirst
//List.iter (printfn "%s\n") matchCollection
Console.ReadLine()

The error I receive is: This value is not a function and cannot be applied (FS0003), and it appears at the List.map allocCreator part. Basically, I want to remove the string that matched from the Match, and keep only the captures in a record.

EDIT: I will try to explain a little more what I wanted to achieve.The Match result will be something like this:

[ "Line 1: Num allocs:3 New:2 Delete:1"; "1"; "3"; "2"; "1"; ]

By using
let matchCollection = [ for m in matches do if m.Success then yield [for l in m.Groups -> l.Value]]
I was trying to get a list of lists ,something like this:

[["Line 1: Num allocs:3 New:2 Delete:1"; "1"; "3"; "2"; "1"; ];["Line 2: Num allocs:3 New:2 Delete:1";"2"; "3"; "2"; "1"; ]; ["Line 3: Num allocs:3 New:2 Delete:1";"3"; "3"; "2"; "1"]]

By using List.map List.tail matchCollection, I was trying to get from the above list, to this:

[["1"; "3"; "2"; "1"; ];["2"; "3"; "2"; "1"; ]; [;"3"; "3"; "2"; "1"]]

And by using List.map allocCreator I was trying to turn the above list into a list of records. I'm kinda new at F# and I probably my logic is wrong, but I don't understand why/where.

EDIT 2: It seems like a precedence issue. If I do this:

let wfirst = List.map allocCreator (List.map List.tail matchCollection);;

Then I get what I needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

慕烟庭风 2024-12-14 21:22:56
let wfirst = List.map allocCreator <| List.map List.tail matchCollection
List.iter (printfn "%A\n") wfirst
let wfirst = List.map allocCreator <| List.map List.tail matchCollection
List.iter (printfn "%A\n") wfirst
一笑百媚生 2024-12-14 21:22:56

不确定您想用该行实现什么目的,但让我们

List.map allocCreater

看看类型并尝试找出答案,这已经是不正确的,map 的第一个参数需要具有类型 'a ->; 'b 但你给出了一个列表,

List.map List.tail matchCollection

这是一个字符串列表列表

我不知道你实际上想在这里得到什么,但你似乎缺少一个函数或太许多清单

Not sure what you are trying to achieve with that line, but lets look at the types to try and figure it out

first

List.map allocCreater

this is already incorrect, the first argument to map needs to have type 'a -> 'b but you have given a list

List.map List.tail matchCollection

this is a string list list

I have no idea what you are actually trying to get at here, but you seem to be short a function or have too many lists

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文