Switch to module over ring for duration arithmetic
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 重构
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 领域
- backend
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- PureScript
- 星标
- 51
- 派生
- 48
- 平均合并
- 2 天 23 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
purescript/purescript-datetime 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 25/100
purescript/purescript-datetime#102 · 5 条评论 ·
-
Add constructors for Date / Time components using type-level integers可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 5/5 一周以上 新手友好度 15/100
purescript/purescript-datetime#96 · 1 条评论 ·
-
type: documentation
难度 2/5 1-3 小时 新手友好度 35/100
purescript/purescript-datetime#92 · 1 条评论 ·
-
status: needs more info
难度 5/5 一周以上 新手友好度 25/100
purescript/purescript-datetime#90 · 3 个 reaction ·
-
status: needs more info
难度 5/5 一周以上 新手友好度 20/100
查看 purescript/purescript-datetime 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
milind-soni/OpenMausBot#5829 ·
维护者通常 1 天内回复