Skip to content

Commit dae2536

Browse files
authored
Merge pull request #40 from purescript/bump
Prepare for 2.0 release
2 parents 0390158 + 3fa686a commit dae2536

File tree

8 files changed

+65
-106
lines changed

8 files changed

+65
-106
lines changed

bower.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-enums": "^1.0.0",
20-
"purescript-functions": "^1.0.0",
21-
"purescript-generics": "^1.0.0",
22-
"purescript-integers": "^1.0.0",
19+
"purescript-enums": "^2.0.0",
20+
"purescript-functions": "^2.0.0",
21+
"purescript-generics": "^3.0.0",
22+
"purescript-integers": "^2.0.0",
2323
"purescript-math": "^2.0.0"
2424
},
2525
"devDependencies": {
26-
"purescript-assert": "^1.0.0",
27-
"purescript-console": "^1.0.0"
26+
"purescript-assert": "^2.0.0",
27+
"purescript-console": "^2.0.0"
2828
}
2929
}

src/Data/Date/Component.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import Data.Maybe (Maybe(..))
1818
-- | acquire a year value from an integer.
1919
newtype Year = Year Int
2020

21-
derive instance eqYear :: Eq Year
22-
derive instance ordYear :: Ord Year
21+
derive newtype instance eqYear :: Eq Year
22+
derive newtype instance ordYear :: Ord Year
2323
derive instance genericYear :: Generic Year
2424

2525
-- Note: these seemingly arbitrary bounds come from relying on JS for date
@@ -122,8 +122,8 @@ instance showMonth :: Show Month where
122122
-- | acquire a day value from an integer.
123123
newtype Day = Day Int
124124

125-
derive instance eqDay :: Eq Day
126-
derive instance ordDay :: Ord Day
125+
derive newtype instance eqDay :: Eq Day
126+
derive newtype instance ordDay :: Ord Day
127127
derive instance genericDay :: Generic Day
128128

129129
instance boundedDay :: Bounded Day where

src/Data/DateTime/Instant.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import Partial.Unsafe (unsafePartial)
2424
-- | `DateTime` type.
2525
newtype Instant = Instant Milliseconds
2626

27-
derive instance eqDateTime :: Eq Instant
28-
derive instance ordDateTime :: Ord Instant
27+
derive newtype instance eqDateTime :: Eq Instant
28+
derive newtype instance ordDateTime :: Ord Instant
2929
derive instance genericDateTime :: Generic Instant
3030

3131
instance boundedInstant :: Bounded Instant where

src/Data/DateTime/Locale.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Control.Comonad (class Comonad, class Extend)
77
import Data.DateTime (Date, Time, DateTime)
88
import Data.Generic (class Generic)
99
import Data.Maybe (Maybe)
10+
import Data.Newtype (class Newtype)
1011
import Data.Time.Duration (Minutes)
1112

1213
-- | A date/time locale specifying an offset in minutes and an optional name for
@@ -23,8 +24,9 @@ instance showLocale :: Show Locale where
2324
-- | The name of a date/time locale. For example: "GMT", "MDT", "CET", etc.
2425
newtype LocaleName = LocaleName String
2526

26-
derive instance eqLocaleName :: Eq LocaleName
27-
derive instance ordLocaleName :: Ord LocaleName
27+
derive instance newtypeLocaleName :: Newtype LocaleName _
28+
derive newtype instance eqLocaleName :: Eq LocaleName
29+
derive newtype instance ordLocaleName :: Ord LocaleName
2830
derive instance genericLocaleName :: Generic LocaleName
2931

3032
instance showLocaleName :: Show LocaleName where

src/Data/Time.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import Data.Enum (fromEnum, toEnum)
1515
import Data.Generic (class Generic)
1616
import Data.Int as Int
1717
import Data.Maybe (fromJust)
18+
import Data.Newtype (unwrap)
1819
import Data.Time.Component (Hour, Millisecond, Minute, Second)
19-
import Data.Time.Duration (class Duration, Days(..), Milliseconds(..), unMilliseconds, fromDuration, toDuration)
20+
import Data.Time.Duration (class Duration, Days(..), Milliseconds(..), fromDuration, toDuration)
2021
import Data.Tuple (Tuple(..))
2122

2223
import Math as Math
@@ -80,7 +81,7 @@ adjust d t =
8081
d' = fromDuration d
8182
tLength = timeToMillis t
8283
dayLength = 86400000.0
83-
wholeDays = Days $ Math.floor (unMilliseconds d' / dayLength)
84+
wholeDays = Days $ Math.floor (unwrap d' / dayLength)
8485
msAdjust = d' - fromDuration wholeDays
8586
msAdjusted = tLength + msAdjust
8687
wrap = if msAdjusted > maxTime then 1.0 else if msAdjusted < -maxTime then -1.0 else 0.0
@@ -100,9 +101,8 @@ timeToMillis t = Milliseconds
100101
+ Int.toNumber (fromEnum (millisecond t))
101102

102103
millisToTime :: Milliseconds -> Time
103-
millisToTime ms =
104+
millisToTime ms@(Milliseconds ms') =
104105
let
105-
ms' = unMilliseconds ms
106106
hourLength = 3600000.0
107107
minuteLength = 60000.0
108108
secondLength = 1000.0

src/Data/Time/Component.purs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import Data.Maybe (Maybe(..))
1919
-- | lowered to a plain integer with the `fromEnum` function.
2020
newtype Hour = Hour Int
2121

22-
derive instance eqHour :: Eq Hour
23-
derive instance ordHour :: Ord Hour
22+
derive newtype instance eqHour :: Eq Hour
23+
derive newtype instance ordHour :: Ord Hour
2424
derive instance genericHour :: Generic Hour
2525

2626
instance boundedHour :: Bounded Hour where
@@ -49,8 +49,8 @@ instance showHour :: Show Hour where
4949
-- | be lowered to a plain integer with the `fromEnum` function.
5050
newtype Minute = Minute Int
5151

52-
derive instance eqMinute :: Eq Minute
53-
derive instance ordMinute :: Ord Minute
52+
derive newtype instance eqMinute :: Eq Minute
53+
derive newtype instance ordMinute :: Ord Minute
5454
derive instance genericMinute :: Generic Minute
5555

5656
instance boundedMinute :: Bounded Minute where
@@ -79,8 +79,8 @@ instance showMinute :: Show Minute where
7979
-- | be lowered to a plain integer with the `fromEnum` function.
8080
newtype Second = Second Int
8181

82-
derive instance eqSecond :: Eq Second
83-
derive instance ordSecond :: Ord Second
82+
derive newtype instance eqSecond :: Eq Second
83+
derive newtype instance ordSecond :: Ord Second
8484
derive instance genericSecond :: Generic Second
8585

8686
instance boundedSecond :: Bounded Second where
@@ -110,8 +110,8 @@ instance showSecond :: Show Second where
110110
-- | function.
111111
newtype Millisecond = Millisecond Int
112112

113-
derive instance eqMillisecond :: Eq Millisecond
114-
derive instance ordMillisecond :: Ord Millisecond
113+
derive newtype instance eqMillisecond :: Eq Millisecond
114+
derive newtype instance ordMillisecond :: Ord Millisecond
115115
derive instance genericMillisecond :: Generic Millisecond
116116

117117
instance boundedMillisecond :: Bounded Millisecond where

src/Data/Time/Duration.purs

Lines changed: 34 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,113 +3,69 @@ module Data.Time.Duration where
33
import Prelude
44

55
import Data.Generic (class Generic)
6+
import Data.Newtype (class Newtype, over)
67

78
-- | A duration measured in milliseconds.
89
newtype Milliseconds = Milliseconds Number
910

10-
unMilliseconds :: Milliseconds -> Number
11-
unMilliseconds (Milliseconds ms) = ms
12-
13-
derive instance eqMilliseconds :: Eq Milliseconds
14-
derive instance ordMilliseconds :: Ord Milliseconds
11+
derive instance newtypeMilliseconds :: Newtype Milliseconds _
1512
derive instance genericMilliseconds :: Generic Milliseconds
16-
17-
instance semiringMilliseconds :: Semiring Milliseconds where
18-
add (Milliseconds x) (Milliseconds y) = Milliseconds (x + y)
19-
mul (Milliseconds x) (Milliseconds y) = Milliseconds (x * y)
20-
zero = Milliseconds 0.0
21-
one = Milliseconds 1.0
22-
23-
instance ringMilliseconds :: Ring Milliseconds where
24-
sub (Milliseconds x) (Milliseconds y) = Milliseconds (x - y)
13+
derive newtype instance eqMilliseconds :: Eq Milliseconds
14+
derive newtype instance ordMilliseconds :: Ord Milliseconds
15+
derive newtype instance semiringMilliseconds :: Semiring Milliseconds
16+
derive newtype instance ringMilliseconds :: Ring Milliseconds
2517

2618
instance showMilliseconds :: Show Milliseconds where
2719
show (Milliseconds n) = "(Milliseconds " <> show n <> ")"
2820

2921
-- | A duration measured in seconds.
3022
newtype Seconds = Seconds Number
3123

32-
unSeconds :: Seconds -> Number
33-
unSeconds (Seconds s) = s
34-
35-
derive instance eqSeconds :: Eq Seconds
36-
derive instance ordSeconds :: Ord Seconds
24+
derive instance newtypeSeconds :: Newtype Seconds _
3725
derive instance genericSeconds :: Generic Seconds
38-
39-
instance semiringSeconds :: Semiring Seconds where
40-
add (Seconds x) (Seconds y) = Seconds (x + y)
41-
mul (Seconds x) (Seconds y) = Seconds (x * y)
42-
zero = Seconds 0.0
43-
one = Seconds 1.0
44-
45-
instance ringSeconds :: Ring Seconds where
46-
sub (Seconds x) (Seconds y) = Seconds (x - y)
26+
derive newtype instance eqSeconds :: Eq Seconds
27+
derive newtype instance ordSeconds :: Ord Seconds
28+
derive newtype instance semiringSeconds :: Semiring Seconds
29+
derive newtype instance ringSeconds :: Ring Seconds
4730

4831
instance showSeconds :: Show Seconds where
4932
show (Seconds n) = "(Seconds " <> show n <> ")"
5033

5134
-- | A duration measured in minutes.
5235
newtype Minutes = Minutes Number
5336

54-
unMinutes :: Minutes -> Number
55-
unMinutes (Minutes m) = m
56-
57-
derive instance eqMinutes :: Eq Minutes
58-
derive instance ordMinutes :: Ord Minutes
37+
derive instance newtypeMinutes :: Newtype Minutes _
5938
derive instance genericMinutes :: Generic Minutes
60-
61-
instance semiringMinutes :: Semiring Minutes where
62-
add (Minutes x) (Minutes y) = Minutes (x + y)
63-
mul (Minutes x) (Minutes y) = Minutes (x * y)
64-
zero = Minutes 0.0
65-
one = Minutes 1.0
66-
67-
instance ringMinutes :: Ring Minutes where
68-
sub (Minutes x) (Minutes y) = Minutes (x - y)
39+
derive newtype instance eqMinutes :: Eq Minutes
40+
derive newtype instance ordMinutes :: Ord Minutes
41+
derive newtype instance semiringMinutes :: Semiring Minutes
42+
derive newtype instance ringMinutes :: Ring Minutes
6943

7044
instance showMinutes :: Show Minutes where
7145
show (Minutes n) = "(Minutes " <> show n <> ")"
7246

7347
-- | A duration measured in hours.
7448
newtype Hours = Hours Number
7549

76-
unHours :: Hours -> Number
77-
unHours (Hours m) = m
78-
79-
derive instance eqHours :: Eq Hours
80-
derive instance ordHours :: Ord Hours
50+
derive instance newtypeHours :: Newtype Hours _
8151
derive instance genericHours :: Generic Hours
82-
83-
instance semiringHours :: Semiring Hours where
84-
add (Hours x) (Hours y) = Hours (x + y)
85-
mul (Hours x) (Hours y) = Hours (x * y)
86-
zero = Hours 0.0
87-
one = Hours 1.0
88-
89-
instance ringHours :: Ring Hours where
90-
sub (Hours x) (Hours y) = Hours (x - y)
52+
derive newtype instance eqHours :: Eq Hours
53+
derive newtype instance ordHours :: Ord Hours
54+
derive newtype instance semiringHours :: Semiring Hours
55+
derive newtype instance ringHours :: Ring Hours
9156

9257
instance showHours :: Show Hours where
9358
show (Hours n) = "(Hours " <> show n <> ")"
9459

9560
-- | A duration measured in days, where a day is assumed to be exactly 24 hours.
9661
newtype Days = Days Number
9762

98-
unDays :: Days -> Number
99-
unDays (Days m) = m
100-
101-
derive instance eqDays :: Eq Days
102-
derive instance ordDays :: Ord Days
63+
derive instance newtypeDays :: Newtype Days _
10364
derive instance genericDays :: Generic Days
104-
105-
instance semiringDays :: Semiring Days where
106-
add (Days x) (Days y) = Days (x + y)
107-
mul (Days x) (Days y) = Days (x * y)
108-
zero = Days 0.0
109-
one = Days 1.0
110-
111-
instance ringDays :: Ring Days where
112-
sub (Days x) (Days y) = Days (x - y)
65+
derive newtype instance eqDays :: Eq Days
66+
derive newtype instance ordDays :: Ord Days
67+
derive newtype instance semiringDays :: Semiring Days
68+
derive newtype instance ringDays :: Ring Days
11369

11470
instance showDays :: Show Days where
11571
show (Days n) = "(Days " <> show n <> ")"
@@ -128,17 +84,17 @@ instance durationMilliseconds :: Duration Milliseconds where
12884
toDuration = id
12985

13086
instance durationSeconds :: Duration Seconds where
131-
fromDuration = Milliseconds <<< (_ * 1000.0) <<< unSeconds
132-
toDuration (Milliseconds ms) = Seconds (ms / 1000.0)
87+
fromDuration = over Seconds (_ * 1000.0)
88+
toDuration = over Milliseconds (_ / 1000.0)
13389

13490
instance durationMinutes :: Duration Minutes where
135-
fromDuration = Milliseconds <<< (_ * 60000.0) <<< unMinutes
136-
toDuration (Milliseconds ms) = Minutes (ms / 60000.0)
91+
fromDuration = over Minutes (_ * 60000.0)
92+
toDuration = over Milliseconds (_ / 60000.0)
13793

13894
instance durationHours :: Duration Hours where
139-
fromDuration = Milliseconds <<< (_ * 3600000.0) <<< unHours
140-
toDuration (Milliseconds ms) = Hours (ms / 3600000.0)
95+
fromDuration = over Hours (_ * 3600000.0)
96+
toDuration = over Milliseconds (_ / 3600000.0)
14197

14298
instance durationDays :: Duration Days where
143-
fromDuration = Milliseconds <<< (_ * 86400000.0) <<< unDays
144-
toDuration (Milliseconds ms) = Days (ms / 86400000.0)
99+
fromDuration = over Days (_ * 86400000.0)
100+
toDuration = over Milliseconds (_ / 86400000.0)

test/Test/Main.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Prelude
55
import Control.Monad.Eff (Eff)
66
import Control.Monad.Eff.Console (CONSOLE, log)
77

8-
import Data.Enum (class BoundedEnum, Cardinality, toEnum, enumFromTo, cardinality, runCardinality, succ, fromEnum, pred)
8+
import Data.Enum (class BoundedEnum, Cardinality, toEnum, enumFromTo, cardinality, succ, fromEnum, pred)
99
import Data.Date as Date
1010
import Data.Time as Time
1111
import Data.Time.Duration as Duration
@@ -14,6 +14,7 @@ import Data.DateTime as DateTime
1414
import Data.DateTime.Instant as Instant
1515
import Data.Maybe (Maybe(..), fromJust)
1616
import Data.Tuple (Tuple(..), snd)
17+
import Data.Newtype (unwrap)
1718

1819
import Type.Proxy (Proxy(..))
1920
import Test.Assert (ASSERT, assert)
@@ -144,5 +145,5 @@ checkBounded _ = do
144145
checkBoundedEnum :: forall e. BoundedEnum e => Proxy e -> Tests
145146
checkBoundedEnum p = do
146147
checkBounded p
147-
let card = runCardinality (cardinality :: Cardinality e)
148+
let card = unwrap (cardinality :: Cardinality e)
148149
assert $ Array.length (enumFromTo bottom (top :: e)) == card

0 commit comments

Comments
 (0)