@@ -17,14 +17,38 @@ import Data.Char (Char(), charString)
1717import Data.String (toCharArray )
1818import Data.Int (Int (), fromNumber , toNumber )
1919
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".
2025newtype 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,
2129newtype Perms = Perms { u :: Perm , g :: Perm , o :: Perm }
2230
31+ -- | No permissions. This is the identity of the Semigroup (<>) operation for
32+ -- | Perm.
33+ none :: Perm
2334none = Perm { r: false , w: false , x: false }
35+
36+ -- | The "readable" permission.
37+ r :: Perm
2438r = Perm { r: true , w: false , x: false }
39+
40+ -- | The "writable" permission.
41+ w :: Perm
2542w = Perm { r: false , w: true , x: false }
43+
44+ -- | The "executable" permission.
45+ x :: Perm
2646x = Perm { r: false , w: false , x: true }
2747
48+ -- | All permissions: readable, writable, and executable.
49+ all :: Perm
50+ all = r <> w <> x
51+
2852instance semigroupPerm :: Semigroup Perm where
2953 (<>) (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
3054 Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
@@ -51,9 +75,13 @@ permFromChar = _perm <<< charString
5175 _perm " 7" = Just $ r <> w <> x
5276 _perm _ = Nothing
5377
78+ -- | Create a `Perm` value. The arguments represent the readable, writable, and
79+ -- | executable permissions respectively.
5480mkPerm :: Boolean -> Boolean -> Boolean -> Perm
5581mkPerm r w x = Perm { r: r, w: w, x: x }
5682
83+ -- | Create a `Perms` value. The arguments represent the user's, group's, and
84+ -- | others' permission sets, respectively.
5785mkPerms :: Perm -> Perm -> Perm -> Perms
5886mkPerms u g o = Perms { u: u, g: g, o: o }
5987
0 commit comments