Switch to module over ring for duration arithmetic
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Refactoring
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Bereich
- backend
Rechercherichtung
The issue names the Semiring instances for Milliseconds and other duration types, and links the modules-over-rings library. Start by locating those instances and reviewing the linked abstraction. The issue proposes replacing them and creating a vector-spaces-over-fields library for division; done means duration arithmetic follows those abstractions without the wrapping shown in the examples.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Currently a Semiring Milliseconds instance exists. However, durations are not a semiring: the closure property of the multiplication operation is not honoured because multiplying two durations gives not a duration but a duration squared.
This is incorrect, and causes awkward code where you need to add/remove nonsensical wrappers just so you can multiply or divide. One example is multiplying a duration by a scalar:
twiceAsLong :: Milliseconds -> Milliseconds
twiceAsLong a = a * Milliseconds 2.0 -- nasty wrap
Another example is where you divide two durations when implementing a multiplication between durations and frequencies where the frequency type is in terms of the reciprocal of the frequency, which is a duration:
newtype Freq = Freq Milliseconds
-- | The reciprocal of a frequency is a duration. (Note how 1/ms = kHz.)
reciprocal :: Freq -> Milliseconds
reciprocal (Freq r) = r
-- | Multiplying a duration (ms) by a frequency (1/ms) gives a number.
multiply :: Milliseconds -> Freq -> Number
multiply d f = un Milliseconds (d / reciprocal f) -- nasty unwrap
With the right abstraction, no wrapping and unwrapping would be necessary, because the types would just work out. We should remove the Semiring Milliseconds instance (and the instances for other duration types) and switch to modules over rings instead, which model this correctly. To add division we should make a library for vector spaces over fields.
Modules over rings and vector spaces over fields are generally useful for types that represent quantities, such as durations, distances, and file sizes.
- Vorherrschende Sprache
- PureScript
- Sterne
- 51
- Forks
- 48
- Ø Merge
- 2 T. 23 Std.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus purescript/purescript-datetime
-
Week number of the YearOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 25/100
purescript/purescript-datetime#102 · 5 Kommentare ·
-
Add constructors for Date / Time components using type-level integersEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 15/100
purescript/purescript-datetime#96 · 1 Kommentar ·
-
type: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 35/100
purescript/purescript-datetime#92 · 1 Kommentar ·
-
status: needs more info
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
purescript/purescript-datetime#90 · 3 Reaktionen ·
-
Addjust by Month, YearOffenstatus: needs more info
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
Alle Issues in purescript/purescript-datetime
Ähnliche Issues
-
ManageSieve proxy: a backend's NO/BYE greeting is skipped as a capability line and reported as EOFOffenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Mend: dependency security vulnerability
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
ManageIQ/manageiq-pods#1476 ·
Maintainer antworten meist innerhalb von 1 Tag
-
mcp: typed tool handlers lose wrapped JSON-RPC errorsEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
modelcontextprotocol/go-sdk#1529 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
FinanceFlash/unvibecode#818 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100