如何修复此 FS00003 错误?
这是我的代码:
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
I was trying to get a list of lists ,something like this:
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"]]
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定您想用该行实现什么目的,但让我们
先
看看类型并尝试找出答案,这已经是不正确的,map 的第一个参数需要具有类型
'a ->; 'b
但你给出了一个列表,这是一个
字符串列表列表
我不知道你实际上想在这里得到什么,但你似乎缺少一个函数或太许多清单
Not sure what you are trying to achieve with that line, but lets look at the types to try and figure it out
first
this is already incorrect, the first argument to map needs to have type
'a -> 'b
but you have given a listthis 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