@@ -12,13 +12,15 @@ module Node.FS.Perms
1212 , permsToInt
1313 ) where
1414
15- import Prelude
15+ import Prelude (class Show , class Ord , class Eq , class Semiring ,
16+ show , otherwise , compare , one , zero ,
17+ (<<<), ($), (<>), (+), (<*>), (<$>), (==), (&&), (||))
1618import Global (readInt )
17- import Data.Maybe (Maybe (..), isNothing )
18- import Data.Maybe.Unsafe (fromJust )
19+ import Data.Maybe (Maybe (..), isNothing , fromJust )
1920import Data.Char (fromCharCode )
2021import Data.String (toCharArray , joinWith , drop , charAt , indexOf )
2122import Data.Int (fromNumber )
23+ import Partial.Unsafe (unsafePartial )
2224
2325-- | A `Perm` value specifies what is allowed to be done with a particular
2426-- | file by a particular class of user — that is, whether it is
@@ -37,17 +39,17 @@ import Data.Int (fromNumber)
3739newtype Perm = Perm { r :: Boolean , w :: Boolean , x :: Boolean }
3840
3941instance eqPerm :: Eq Perm where
40- eq (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
42+ eq (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4143 r1 == r2 && w1 == w2 && x1 == x2
4244
4345instance ordPerm :: Ord Perm where
44- compare (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
46+ compare (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4547 compare [r1, w1, x1] [r2, w2, x2]
4648
4749instance showPerm :: Show Perm where
4850 show p | p == none = " none"
4951 show p | p == all = " all"
50- show (Perm { r = r, w = w, x = x }) =
52+ show (Perm { r: r, w: w, x: x }) =
5153 joinWith " + " ps
5254 where
5355 ps =
@@ -56,10 +58,10 @@ instance showPerm :: Show Perm where
5658 (if x then [" execute" ] else [] )
5759
5860instance semiringPerm :: Semiring Perm where
59- add (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
61+ add (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6062 Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
6163 zero = Perm { r: false , w: false , x: false }
62- mul (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
64+ mul (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6365 Perm { r: r0 && r1, w: w0 && w1, x: x0 && x1 }
6466 one = Perm { r: true , w: true , x: true }
6567
@@ -97,15 +99,15 @@ all = one
9799newtype Perms = Perms { u :: Perm , g :: Perm , o :: Perm }
98100
99101instance eqPerms :: Eq Perms where
100- eq (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
102+ eq (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
101103 u1 == u2 && g1 == g2 && o1 == o2
102104
103105instance ordPerms :: Ord Perms where
104- compare (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
106+ compare (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
105107 compare [u1, g1, o1] [u2, g2, o2]
106108
107109instance showPerms :: Show Perms where
108- show (Perms { u = u, g = g, o = o }) =
110+ show (Perms { u: u, g: g, o: o }) =
109111 " mkPerms " <> joinWith " " (f <$> [u, g, o])
110112 where
111113 f perm = let str = show perm
@@ -154,7 +156,7 @@ mkPerms u g o = Perms { u: u, g: g, o: o }
154156-- | * `permToInt w == 2`
155157-- | * `permToInt (r + w) == 6`
156158permToInt :: Perm -> Int
157- permToInt (Perm { r = r, w = w, x = x }) =
159+ permToInt (Perm { r: r, w: w, x: x }) =
158160 (if r then 4 else 0 )
159161 + (if w then 2 else 0 )
160162 + (if x then 1 else 0 )
@@ -167,12 +169,12 @@ permToString = show <<< permToInt
167169-- | accepted by `chmod`. For example:
168170-- | `permsToString (mkPerms (read + write) read read) == "0644"`
169171permsToString :: Perms -> String
170- permsToString (Perms { u = u, g = g, o = o }) =
172+ permsToString (Perms { u: u, g: g, o: o }) =
171173 " 0"
172- ++ permToString u
173- ++ permToString g
174- ++ permToString o
174+ <> permToString u
175+ <> permToString g
176+ <> permToString o
175177
176178-- | Convert a `Perms` value to an `Int`, via `permsToString`.
177179permsToInt :: Perms -> Int
178- permsToInt = fromJust <<< fromNumber <<< readInt 8 <<< permsToString
180+ permsToInt = unsafePartial $ fromJust <<< fromNumber <<< readInt 8 <<< permsToString
0 commit comments