Home > Software engineering >  ToArray and ToString return (unit -> string), not string. What should I do?
ToArray and ToString return (unit -> string), not string. What should I do?

Time:10-24

Notes

I'm currently having a problem with the functions "ToString" returning a (unit -> string) type and not a string, and "ToArray" returning (unit -> string[]) and not string[]. Attempting to upcast to string[] or string has no success.

Here is the code:

let readZip filepath = ZipFile.OpenRead filepath
let replaceEnvs str = Environment.ExpandEnvironmentVariables str

let listFiles rawDir =
    replaceEnvs rawDir
    |> Directory.EnumerateFiles

let readModMetadata filepath =
    let archive = readZip filepath
    (archive.GetEntry "mcmod.info").ToString    // Also becomes (unit -> string) and not string

[<EntryPoint>]
let main args =
    let mods = listFiles modsFolder
    let modAsArray = mods.ToArray   // Becomes (unit -> string[]) and not string[]?
    0

Why is this so, and is there a way to get only strings?

CodePudding user response:

So I found it out.

You need to specify that no parameters go into the functions. The parenthesis in ToString() do just that. I need more coffee.

  • Related