How can I fix this FS00003 error?
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.
let wfirst = List.map allocCreator <| List.map List.tail matchCollection
List.iter (printfn "%A\n") wfirst
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
精彩评论