Hacker News new | past | comments | ask | show | jobs | submit login

Type refinements are a great concept and I'd love to see them in Rust. And double-refinement types are great for helping with conversions, such as with Rust From/Into, and potentially a dynamic converter function.

Examples of double-refinements that I'd like:

- Common units like Length:Meter and Length:Foot.

- Color bits like Color:RGB24 and Color:CYMK24.

- Worldwide currency like Money:USD and Money:GBP with a converter function that knows exchange rates.

- Human languages like String:English vs String:Cymraeg with a converter function that knows translations.




> - Worldwide currency like Money:USD and Money:GBP with a converter function that knows exchange rates.

Exchange rates vary over time, so you'd arguably need a type which includes a timestamp (e.g. "USD 1000 at 2024-12-25").

And that's ignoring all these other complexities such as the spread, different currency converters offering differing rates, unofficial and multiple official rates in countries with currency controls (e.g. Argentina), hedging, etc


Plus, perhaps the biggest complexity of all is that the currency rates are often not free, particularly if you want "live pricing" (updated every few seconds), and particularly if it's for commercial use. And, the fact that they may or may not be free, also illustrates well the fact that there are no definitive rates, there are only "rates according to X".


> multiple official rates

One such case is customs agencies publishing their own exchange rates for use in custom declarations, for example here[1] for the US or here[2] for Sweden.

[1]: https://www.cbp.gov/trade/document/report/daily-foreign-curr...

[2]: https://tulltaxan.tullverket.se/arctictariff-public-web/#!/t...


The currency converter is the odd one out because it context dependent. (Time, contract, etc)


Similar to time with a timezone?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: