@@ -17,14 +17,38 @@ import Data.Char (Char(), charString)
17
17
import Data.String (toCharArray )
18
18
import Data.Int (Int (), fromNumber , toNumber )
19
19
20
+ -- | A `Perm` value specifies what is allowed to be done with a particular
21
+ -- | file by a particular class of user — that is, whether it is
22
+ -- | readable, writable, and/or executable. It has a semigroup instance, which
23
+ -- | allows you to combine permissions; for example, `r <> w` means "readable
24
+ -- | and writable".
20
25
newtype Perm = Perm { r :: Boolean , w :: Boolean , x :: Boolean }
26
+
27
+ -- | A `Perms` value includes all the permissions information about a
28
+ -- | particular file or directory,
21
29
newtype Perms = Perms { u :: Perm , g :: Perm , o :: Perm }
22
30
31
+ -- | No permissions. This is the identity of the Semigroup (<>) operation for
32
+ -- | Perm.
33
+ none :: Perm
23
34
none = Perm { r: false , w: false , x: false }
35
+
36
+ -- | The "readable" permission.
37
+ r :: Perm
24
38
r = Perm { r: true , w: false , x: false }
39
+
40
+ -- | The "writable" permission.
41
+ w :: Perm
25
42
w = Perm { r: false , w: true , x: false }
43
+
44
+ -- | The "executable" permission.
45
+ x :: Perm
26
46
x = Perm { r: false , w: false , x: true }
27
47
48
+ -- | All permissions: readable, writable, and executable.
49
+ all :: Perm
50
+ all = r <> w <> x
51
+
28
52
instance semigroupPerm :: Semigroup Perm where
29
53
(<>) (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
30
54
Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
@@ -51,9 +75,13 @@ permFromChar = _perm <<< charString
51
75
_perm " 7" = Just $ r <> w <> x
52
76
_perm _ = Nothing
53
77
78
+ -- | Create a `Perm` value. The arguments represent the readable, writable, and
79
+ -- | executable permissions respectively.
54
80
mkPerm :: Boolean -> Boolean -> Boolean -> Perm
55
81
mkPerm r w x = Perm { r: r, w: w, x: x }
56
82
83
+ -- | Create a `Perms` value. The arguments represent the user's, group's, and
84
+ -- | others' permission sets, respectively.
57
85
mkPerms :: Perm -> Perm -> Perm -> Perms
58
86
mkPerms u g o = Perms { u: u, g: g, o: o }
59
87
0 commit comments