I am new to F#, and I'd love to get some help :)
I have ? compilation error on this code, and I can't figure it out:
printfn "Please enter the path for the Jack file/s directory"
let dir = System.Console.ReadLine()
let jackFiles : List<String> = (new List<String>())
dir
|> Directory.GetFiles
|> Seq.iteri(fun file -> if ((Path.GetExtension(file)).Equals(".jack")) then JackFiles.Add(file))
The compiler shouts this error:
This expression was expected to have type
string->unitbut here has typeunit
about the if ((Path.GetExtension(file)).Equals(".jack")) then JackFiles.Add(file)) part...
Why is it wrong and how do I fix it?
The function argument to
Seq.iterirequires two arguments and should have type(int -> 'T -> unit). Its file parameter is inferred to have typeintand therefore yourifstatement should have typestring -> unitbut actually has typeunit, hence the error.It looks like you don't require the
intargument so you can useSeq.iterinstead.However it looks like what you're trying to do could be done using something similar to: