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 mixed units #364

Closed
bsidhom opened this issue Feb 21, 2024 · 4 comments
Closed

Support mixed units #364

bsidhom opened this issue Feb 21, 2024 · 4 comments
Labels

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

@sharkdp sharkdp changed the title Support unit lists Support mixed units Jul 1, 2024
@sharkdp
Copy link
Owner

sharkdp commented Jul 24, 2024

I am planning to add rudimentary support for (some) mixed unit representations in #501

@sharkdp
Copy link
Owner

sharkdp commented Aug 9, 2024

Tenatively closing this for now, even if it feels not really "native" yet.

@sharkdp
Copy link
Owner

sharkdp commented Oct 8, 2024

Reopening this just to close it again, now that we have a much nicer solution, thanks to @Goju-Ryu: https://numbat.dev/doc/list-functions-other.html?highlight=dms#mixed-unit-conversion

@sharkdp sharkdp closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants