Skip to content

Commit 9b11c60

Browse files
authored
Merge pull request #30 from kika/purescript-0.9.1
Purescript 0.9.1 update
2 parents 375c76e + 124b57f commit 9b11c60

File tree

12 files changed

+161
-142
lines changed

12 files changed

+161
-142
lines changed

bower.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-datetime": "^0.9.0",
19-
"purescript-foreign": "^0.7.0",
20-
"purescript-node-buffer": "^0.2.0",
21-
"purescript-node-path": "^0.4.0",
22-
"purescript-unsafe-coerce": "^0.1.0",
23-
"purescript-nullable": "~0.2.1",
24-
"purescript-node-streams": "~0.4.0",
25-
"purescript-exceptions": "~0.3.3"
18+
"purescript-datetime": "^1.0.0",
19+
"purescript-foreign": "^1.0.0",
20+
"purescript-node-buffer": "^1.0.0",
21+
"purescript-node-path": "^1.0.0",
22+
"purescript-unsafe-coerce": "^1.0.0",
23+
"purescript-nullable": "^1.0.0",
24+
"purescript-node-streams": "^1.0.0",
25+
"purescript-exceptions": "^1.0.0",
26+
"purescript-js-date": "^1.0.0",
27+
"purescript-globals": "^1.0.0"
2628
},
2729
"devDependencies": {
28-
"purescript-console": "~0.1.1"
30+
"purescript-console": "^1.0.0"
2931
},
3032
"repository": {
3133
"type": "git",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"pulp": "^8.1.0",
4+
"pulp": "^9.0.1",
55
"bower": "^1.7.7"
66
},
77
"scripts": {

src/Node/FS/Async.purs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,27 @@ module Node.FS.Async
3232
) where
3333

3434
import Prelude
35-
import Control.Monad.Eff
35+
import Control.Monad.Eff (Eff, runPure)
3636
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
37-
import Control.Monad.Eff.Exception
38-
import Data.Date
39-
import Data.Time
40-
import Data.Either
41-
import Data.Function
42-
import Data.Maybe
43-
import Data.Nullable
37+
import Control.Monad.Eff.Exception (Error)
38+
import Data.DateTime (DateTime)
39+
import Data.Time.Duration (Milliseconds(..))
40+
import Data.DateTime.Instant (fromDateTime, unInstant)
41+
import Data.Either (Either(..))
42+
import Data.Function.Uncurried (Fn2, Fn6, Fn4, Fn3,
43+
runFn2, runFn6, runFn4, runFn3)
44+
import Data.Maybe (Maybe(..))
45+
import Data.Nullable (Nullable, toNullable)
4446
import Node.Buffer (Buffer(), BUFFER(), size)
4547
import Data.Int (round)
46-
import Node.Encoding
47-
import Node.FS
48-
import Node.FS.Stats
48+
import Node.Encoding (Encoding)
49+
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
50+
BufferOffset, FileMode, FileFlags, SymlinkType,
51+
fileFlagsToNode, symlinkTypeToNode)
52+
import Node.FS.Stats (StatsObj, Stats(..))
4953
import Node.Path (FilePath())
50-
import Node.FS.Perms
51-
import Node.FS.Internal
54+
import Node.FS.Perms (Perms, permsToString, all, mkPerms)
55+
import Node.FS.Internal (mkEff, unsafeRequireFS)
5256

5357
type JSCallback a = Fn2 (Nullable Error) a Unit
5458

@@ -221,8 +225,8 @@ readdir file cb = mkEff $ \_ -> runFn2
221225

222226
-- | Sets the accessed and modified times for the specified file.
223227
utimes :: forall eff. FilePath
224-
-> Date
225-
-> Date
228+
-> DateTime
229+
-> DateTime
226230
-> Callback eff Unit
227231
-> Eff (fs :: FS | eff) Unit
228232

@@ -234,6 +238,7 @@ utimes file atime mtime cb = mkEff $ \_ -> runFn4
234238
where
235239
fromDate date = ms (toEpochMilliseconds date) / 1000
236240
ms (Milliseconds n) = round n
241+
toEpochMilliseconds = unInstant <<< fromDateTime
237242

238243
-- | Reads the entire contents of a file returning the result as a raw buffer.
239244
readFile :: forall eff. FilePath

src/Node/FS/Internal.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
module Node.FS.Internal where
33

44
import Prelude
5-
import Control.Monad.Eff
6-
import Unsafe.Coerce
5+
import Control.Monad.Eff (Eff)
6+
import Unsafe.Coerce (unsafeCoerce)
77

88
mkEff :: forall e a. (Unit -> a) -> Eff e a
99
mkEff = unsafeCoerce

src/Node/FS/Perms.purs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ module Node.FS.Perms
1414

1515
import Prelude
1616
import Global (readInt)
17-
import Data.Maybe (Maybe(..), isNothing)
18-
import Data.Maybe.Unsafe (fromJust)
17+
import Data.Maybe (Maybe(..), isNothing, fromJust)
1918
import Data.Char (fromCharCode)
2019
import Data.String (toCharArray, joinWith, drop, charAt, indexOf)
2120
import Data.Int (fromNumber)
21+
import Partial.Unsafe (unsafePartial)
2222

2323
-- | A `Perm` value specifies what is allowed to be done with a particular
2424
-- | file by a particular class of user &mdash; that is, whether it is
@@ -37,17 +37,17 @@ import Data.Int (fromNumber)
3737
newtype Perm = Perm { r :: Boolean, w :: Boolean, x :: Boolean }
3838

3939
instance eqPerm :: Eq Perm where
40-
eq (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
40+
eq (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4141
r1 == r2 && w1 == w2 && x1 == x2
4242

4343
instance ordPerm :: Ord Perm where
44-
compare (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
44+
compare (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4545
compare [r1, w1, x1] [r2, w2, x2]
4646

4747
instance showPerm :: Show Perm where
4848
show p | p == none = "none"
4949
show p | p == all = "all"
50-
show (Perm { r = r, w = w, x = x }) =
50+
show (Perm { r: r, w: w, x: x }) =
5151
joinWith " + " ps
5252
where
5353
ps =
@@ -56,10 +56,10 @@ instance showPerm :: Show Perm where
5656
(if x then ["execute"] else [])
5757

5858
instance semiringPerm :: Semiring Perm where
59-
add (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
59+
add (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6060
Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
6161
zero = Perm { r: false, w: false, x: false }
62-
mul (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
62+
mul (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6363
Perm { r: r0 && r1, w: w0 && w1, x: x0 && x1 }
6464
one = Perm { r: true, w: true, x: true }
6565

@@ -97,15 +97,15 @@ all = one
9797
newtype Perms = Perms { u :: Perm, g :: Perm, o :: Perm }
9898

9999
instance eqPerms :: Eq Perms where
100-
eq (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
100+
eq (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
101101
u1 == u2 && g1 == g2 && o1 == o2
102102

103103
instance ordPerms :: Ord Perms where
104-
compare (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
104+
compare (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
105105
compare [u1, g1, o1] [u2, g2, o2]
106106

107107
instance showPerms :: Show Perms where
108-
show (Perms { u = u, g = g, o = o }) =
108+
show (Perms { u: u, g: g, o: o }) =
109109
"mkPerms " <> joinWith " " (f <$> [u, g, o])
110110
where
111111
f perm = let str = show perm
@@ -154,7 +154,7 @@ mkPerms u g o = Perms { u: u, g: g, o: o }
154154
-- | * `permToInt w == 2`
155155
-- | * `permToInt (r + w) == 6`
156156
permToInt :: Perm -> Int
157-
permToInt (Perm { r = r, w = w, x = x }) =
157+
permToInt (Perm { r: r, w: w, x: x }) =
158158
(if r then 4 else 0)
159159
+ (if w then 2 else 0)
160160
+ (if x then 1 else 0)
@@ -167,12 +167,12 @@ permToString = show <<< permToInt
167167
-- | accepted by `chmod`. For example:
168168
-- | `permsToString (mkPerms (read + write) read read) == "0644"`
169169
permsToString :: Perms -> String
170-
permsToString (Perms { u = u, g = g, o = o }) =
170+
permsToString (Perms { u: u, g: g, o: o }) =
171171
"0"
172-
++ permToString u
173-
++ permToString g
174-
++ permToString o
172+
<> permToString u
173+
<> permToString g
174+
<> permToString o
175175

176176
-- | Convert a `Perms` value to an `Int`, via `permsToString`.
177177
permsToInt :: Perms -> Int
178-
permsToInt = fromJust <<< fromNumber <<< readInt 8 <<< permsToString
178+
permsToInt = unsafePartial $ fromJust <<< fromNumber <<< readInt 8 <<< permsToString

src/Node/FS/Stats.purs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ module Node.FS.Stats
1414
) where
1515

1616
import Prelude
17-
import Data.Date
18-
import Data.Function
19-
import Data.Maybe.Unsafe (fromJust)
17+
import Data.DateTime (DateTime)
18+
import Data.Function.Uncurried (Fn2, Fn0, runFn2)
19+
import Data.JSDate (JSDate, toDateTime)
20+
import Data.Maybe (fromJust)
21+
import Partial.Unsafe (unsafePartial)
2022

2123
type StatsObj =
2224
{ dev :: Number
@@ -44,7 +46,7 @@ data Stats = Stats StatsObj
4446
foreign import showStatsObj :: StatsObj -> String
4547

4648
instance showStats :: Show Stats where
47-
show (Stats o) = "Stats " ++ showStatsObj o
49+
show (Stats o) = "Stats " <> showStatsObj o
4850

4951
foreign import statsMethod :: Fn2 String StatsObj Boolean
5052

@@ -69,11 +71,11 @@ isSocket (Stats s) = runFn2 statsMethod "isSocket" s
6971
isSymbolicLink :: Stats -> Boolean
7072
isSymbolicLink (Stats s) = runFn2 statsMethod "isSymbolicLink" s
7173

72-
accessedTime :: Stats -> Date
73-
accessedTime (Stats s) = fromJust (fromJSDate s.atime)
74+
accessedTime :: Stats -> DateTime
75+
accessedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.atime)
7476

75-
modifiedTime :: Stats -> Date
76-
modifiedTime (Stats s) = fromJust (fromJSDate s.mtime)
77+
modifiedTime :: Stats -> DateTime
78+
modifiedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.mtime)
7779

78-
statusChangedTime :: Stats -> Date
79-
statusChangedTime (Stats s) = fromJust (fromJSDate s.ctime)
80+
statusChangedTime :: Stats -> DateTime
81+
statusChangedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.ctime)

src/Node/FS/Stream.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ module Node.FS.Stream
1515

1616
import Prelude
1717
import Data.Maybe (Maybe(..))
18-
import Data.Function
19-
import Data.Nullable
20-
import Control.Monad.Eff
18+
import Data.Function.Uncurried (Fn2, runFn2)
19+
import Data.Nullable (Nullable, toNullable)
20+
import Control.Monad.Eff (Eff)
2121
import Node.Stream (Readable(), Writable())
2222
import Node.Path (FilePath())
2323

24-
import Node.FS
24+
import Node.FS (FS, FileDescriptor, FileFlags(..), fileFlagsToNode)
2525
import Node.FS.Perms (Perms())
2626
import Node.FS.Perms as Perms
27-
import Node.FS.Internal
27+
import Node.FS.Internal (mkEff, unsafeRequireFS)
2828

2929
fs ::
3030
{ createReadStream :: forall eff opts. Fn2 (Nullable FilePath) { | opts } (Readable () (fs :: FS | eff))

src/Node/FS/Sync.purs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ module Node.FS.Sync
3232
) where
3333

3434
import Prelude
35-
import Control.Monad.Eff
36-
import Control.Monad.Eff.Exception
37-
import Data.Date
38-
import Data.Time
39-
import Data.Function
35+
import Control.Monad.Eff (Eff)
36+
import Control.Monad.Eff.Exception (EXCEPTION)
37+
import Data.DateTime (DateTime)
38+
import Data.Time.Duration (Milliseconds(..))
39+
import Data.DateTime.Instant (fromDateTime, unInstant)
40+
import Data.Function.Uncurried (Fn1, Fn5, Fn3, Fn2,
41+
runFn1, runFn5, runFn3, runFn2)
4042
import Data.Nullable (Nullable(), toNullable)
4143
import Data.Int (round)
4244
import Data.Maybe (Maybe(..))
4345
import Node.Buffer (Buffer(), BUFFER(), size)
44-
import Node.Encoding
46+
import Node.Encoding (Encoding)
4547

46-
import Node.FS
47-
import Node.FS.Stats
48+
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
49+
BufferOffset, FileMode, FileFlags, SymlinkType,
50+
fileFlagsToNode, symlinkTypeToNode)
51+
import Node.FS.Stats (StatsObj, Stats(..))
4852
import Node.Path (FilePath())
49-
import Node.FS.Perms
50-
import Node.FS.Internal
53+
import Node.FS.Perms (Perms, permsToString, all, mkPerms)
54+
import Node.FS.Internal (mkEff, unsafeRequireFS)
5155

5256
fs ::
5357
{ renameSync :: Fn2 FilePath FilePath Unit
@@ -193,8 +197,8 @@ readdir file = mkEff $ \_ -> runFn1
193197

194198
-- | Sets the accessed and modified times for the specified file.
195199
utimes :: forall eff. FilePath
196-
-> Date
197-
-> Date
200+
-> DateTime
201+
-> DateTime
198202
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
199203

200204
utimes file atime mtime = mkEff $ \_ -> runFn3
@@ -204,6 +208,7 @@ utimes file atime mtime = mkEff $ \_ -> runFn3
204208
where
205209
fromDate date = ms (toEpochMilliseconds date) / 1000
206210
ms (Milliseconds n) = round n
211+
toEpochMilliseconds = unInstant <<< fromDateTime
207212

208213
-- | Reads the entire contents of a file returning the result as a raw buffer.
209214
readFile :: forall eff. FilePath

test/Main.purs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
module Test.Main where
22

33
import Prelude
4-
import qualified Test as Test
5-
import qualified TestAsync as TestAsync
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (CONSOLE)
6+
import Control.Monad.Eff.Exception (EXCEPTION)
7+
import Node.FS (FS)
8+
import Node.Buffer (BUFFER)
9+
import Test as Test
10+
import TestAsync as TestAsync
611
import Test.Streams as Streams
712

13+
main::forall e. Eff (fs :: FS , console :: CONSOLE ,
14+
err :: EXCEPTION , buffer :: BUFFER | e) Unit
815
main = do
916
Test.main
1017
TestAsync.main

test/Streams.purs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
module Test.Streams where
22

33
import Prelude
4-
import Data.Maybe
5-
import Data.Either
6-
import Control.Apply ((*>))
7-
import Control.Bind ((=<<))
8-
import Control.Monad.Eff
9-
import Control.Monad.Eff.Exception
10-
import Control.Monad.Eff.Console (log)
11-
import Node.Encoding
12-
import Node.Buffer as Buffer
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (log, CONSOLE)
6+
import Control.Monad.Eff.Exception (EXCEPTION)
7+
import Node.Encoding (Encoding(..))
138
import Node.Path as Path
149
import Node.Stream as Stream
15-
import Unsafe.Coerce
1610

17-
import Node.FS
18-
import Node.FS.Stats
19-
import Node.FS.Stream
11+
import Node.FS (FS)
12+
import Node.FS.Stream (createWriteStream, createReadStream)
2013
import Node.FS.Sync as Sync
2114

15+
main::forall e. Eff (fs::FS, console::CONSOLE, err::EXCEPTION | e) Unit
2216
main = do
2317
let fp = Path.concat
2418

0 commit comments

Comments
 (0)