-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystem.fs
More file actions
58 lines (39 loc) · 1.95 KB
/
FileSystem.fs
File metadata and controls
58 lines (39 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module FileSystem
(*
This module provides a type FsTree. We often refer to elements of
this type as filesystems. But FsTree is just a datatype of certain
trees.
In particular, there is no difference between files and directories
in this representation. We often refer to a node in the tree as a
directory.
This module also provides incomplete definitions of certain
functions operating on filesystems. Note that you have to define
the required FsCheck properties against these functions.
*)
type Path = string list
type FsTree = { name : string
; children : FsTree list }
// Evaluates to true on those FsTree that consist of only the root
// node (i.e., without any child nodes)
let isEmpty (fs : FsTree) : bool = fs.children.IsEmpty
// The list of paths to all of the directories in the filesystem
let show (fs : FsTree) : Path list =
let rec paths (fileSystem: FsTree) (prefix: Path): Path list =
match fileSystem.children with
| [] -> [[fileSystem.name]]
| children ->
let newPrefix = prefix @ [fileSystem.name]
let currentPaths = children |> List.fold(fun state item -> state @ paths item (newPrefix @ [item.name])) [newPrefix]
// let currentPaths = children |> List.fold(fun state item -> state @ paths item prefix) []
currentPaths
paths fs []
// Create a new directory at path p in the silesystem fs. If the
// directory exists, then return the filesystem as is.
let create (p : Path) (fs : FsTree) : FsTree =
failwith "not implemented"
// Delete the directory at path p in the filesystem fs. If the
// directory does not exist, then return the filesystem as is. If the
// path p denotes the root node of the filesystem, then return the
// filesystem as is.
let delete (p : Path) (fs : FsTree) : FsTree =
failwith "not implemented"