Switch to module over ring for duration arithmetic
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Ambito
- backend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PureScript
- Stelle
- 51
- Fork
- 48
- Merge medio
- 2g 23h
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di purescript/purescript-datetime
-
Week number of the YearAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
purescript/purescript-datetime#102 · 5 commenti ·
-
Add constructors for Date / Time components using type-level integersForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
purescript/purescript-datetime#96 · 1 commento ·
-
type: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
purescript/purescript-datetime#92 · 1 commento ·
-
status: needs more info
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
purescript/purescript-datetime#90 · 3 reazioni ·
-
Addjust by Month, YearApertastatus: needs more info
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
Tutte le issue di purescript/purescript-datetime
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
remove the use of `forget`Apertagood first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
milind-soni/OpenMausBot#5829 ·
I maintainer di solito rispondono entro 1 giorno