Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unit lists #364

Open
bsidhom opened this issue Feb 21, 2024 · 1 comment
Open

Support unit lists #364

bsidhom opened this issue Feb 21, 2024 · 1 comment

Comments

@bsidhom
Copy link

bsidhom commented Feb 21, 2024

It would be great if Numbat supported unit lists out of the box à la Gnu Units. This allows units to be displayed in an effectively arbitrary "base" consisting of other units.

I understand that this may be tricky or conceptually incompatible with unit typing, but maybe it could make sense to have some short-hand to define unit list functions that convert to String. I'm thinking of something similar to the human() time function, which currently does this manually in a pretty janky way. (Perhaps the real issue is that custom functions don't have the greatest ergonomics; I'll start a discussion expanding on that.)

Could be nice to have proper support for unit lists as typed entities, though I haven't put much thought into whether that makes sense.

@sharkdp
Copy link
Owner

sharkdp commented Feb 21, 2024

Qalculate calls this feature "mixed units". You can convert heights to "feet + inch" and times to "hours + minutes + seconds", etc.

I agree it would be nice to support this out-of-the-box, without having to write functions like human.

this may be tricky or conceptually incompatible with unit typing

Good thing Numbat is not based on "unit types", but on "dimension types" 😄 [1] [2]. But seriously: I don't think our type system is going to be the problem. If anything, it helps. It makes sense to convert a height to [feet, inch] where all units are of type Length. Or a time to [hours, minutes, seconds] where all units are of type Time. It does not make sense to convert a length to, say, [feet, second].

Concerning syntax, I'm thinking we could do one of the following

length -> [feet, inch]
length -> feet + inch

The latter might be more intuitive, but the former makes more sense from a language-design perspective, I believe.

[1] https://numbat.dev/articles/intro.html
[2] https://numbat.dev/doc/type-system.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants