I would like to use a discriminated union to represent a files and directories. Then given a directory I would like to make a list of all files in it (recursively).
But in the line List.iter makeFileList
I get :
Type mismatch. Expecting a FileOrDir -> unit but given a FileOrDir -> string list. The type 'unit' does not match the type 'string list'
type FileOrDir =
| File of string
| Directory of string * FileOrDir list
let example = Directory("Directory1",[File("file1.txt"); File("file2.txt"); Directory("EmptyDir",[])])
let rec makeFileList fad =
[
match fad with
| File(name) -> yield name
| Directory(name,listOfFiles)
-> listOfFiles |> List.iter makeFileList
]
I would appreciate both the explanation and the solution.