purescript-datetime
purescript-datetime copied to clipboard
Implement type-safe constructors for components
Description of the change
Fixes #96. I did not implement an exactDate'
(see canonicalDate'
for comparison). Since we don't currently have a Prim.Int (class Mod)
, we can't define a type-level computation that guarantees that a given day falls within a given year-month combo. So, the best we could write right now would be:
exactDate'
:: forall year month day
. Reflectable year Int
=> PI.Compare year (-271821) PO.GT
=> PI.Compare year 275760 PO.LT
=> Reflectable month Int
=> PI.Compare month 0 PO.GT
=> PI.Compare month 13 PO.LT
=> Reflectable day Int
=> PI.Compare day 0 PO.GT
=> PI.Compare day 32 PO.LT
=> Proxy year
-> Proxy month
-> Proxy day
-> Date
exactDate' y m d = Date (DC.year y) (DC.month m) (DC.day d)
If we implemented exactDate'
as it is defined above right now, and Prim.Int (class Mod)
is implemented later in the 0.15.x
PureScript series, changing the definition would be a breaking change. But if we leave it out for now, we can add it as a non-breaking change later as:
exactDate'
:: forall year month day maxDay dayUpper
. Reflectable year Int
...
=> MaxDay year month maxDay
=> PI.Add maxDay 1 dayUpper
=> PI.Compare day 0 PO.GT
=> PI.Compare day dayUpper PO.LT
=> Proxy year
-> Proxy month
-> Proxy day
-> Date
exactDate' y m d = Date (DC.year y) (DC.month m) (DC.day d)
Checklist:
- [x] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
- [x] Linked any existing issues or proposals that this pull request should close
- [ ] Updated or added relevant documentation
- [ ] Added a test for the contribution (if applicable)
Locally, this fails to build due to the following compiler error:
[1/1 NoInstanceFound] src/Data/Date.purs:78:39
78 canonicalDate' y m d = canonicalDate (DC.year y) (DC.month m) (DC.day d)
^^^^^^^^^
No type class instance was found for
Prim.Int.Compare year3
-271821
GT
while applying a function year
of type Reflectable @Int t0 Int => Add -271820 -1 t1 => Compare t0 t1 GT => Add -271820 1 t2 => Compare t0 t2 LT => Proxy @Int t0 -> Year
to argument y
while checking that expression year y
has type Year
in value declaration canonicalDate'
where year3 is a rigid type variable
bound at (line 0, column 0 - line 0, column 0)
t0 is an unknown type
t1 is an unknown type
t2 is an unknown type
This fails on both 0.15.0
and 0.15.1
.