serokell / o-clock

:hourglass: Type-safe time units in Haskell
Mozilla Public License 2.0
49 stars 6 forks source link

Durations form a vector space #127

Open treeowl opened 2 years ago

treeowl commented 2 years ago

If we admit negative durations (e.g., X happened -1 seconds after Y = X happened 1 second before y), then durations form a vector space. I don't know enough about vector space classes available on Hackage, but we could instantiate them ... if we admitted negative Time. I don't understand why it's not allowed.

dcastro commented 2 years ago

I'm not familiar with vector spaces, but I too have previously wondered why negative durations are not allowed, and the initial rationale has not been documented anywhere (AFAIK).

To give a concrete use case, this would be useful to calculate the period between two events t0 and t1 where you don't know which event will happen first (i.e. t1 - t0 could be positive or negative).

Also, another related issue: https://github.com/serokell/o-clock/issues/118

However, doing this at this stage would be a significant breaking change. @gromakovsky what do you think about this?