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->unit
but 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.iteri
requires two arguments and should have type(int -> 'T -> unit)
. Its file parameter is inferred to have typeint
and therefore yourif
statement should have typestring -> unit
but actually has typeunit
, hence the error.It looks like you don't require the
int
argument so you can useSeq.iter
instead.However it looks like what you're trying to do could be done using something similar to: