top | item 38294823

(no title)

sharkdp | 2 years ago

I looked at Julia and Unitful.jl quite a bit when designing Numbat. It looks great.

> Extending it to cover all of Numbat's functionality could be trivially accomplished in a few lines.

Look, I'm not claiming that Numbat is superior. But I think Numbat might have its own little niche. And even if not, it's always good to have alternative solutions available.

- Numbat is specifically designed to handle physical dimensions and units. It has a special syntax to give developers the best experience when dealing with units. You can just type "KiB" and have it be parsed as kibibytes. You can use the "->" operator to convert to other units. You can directly annotate functions with physical dimensions ("fn kinetic_energy(m: Mass, v: Velocity) -> Energy = …"). Other languages and their unit libraries might have the same functionality, but it has always been added as an afterthought.

- Numbat has a static type system, Julia's is dynamic.

- Numbat can be compiled to Web Assembly and you can run it in your browser. I'm not sure if that is possible with Julia?

- Numbat might eventually be able to infer (physical dimension) function parameter types with its Hindley-Milner-style type system [1]. The only language that I know of that can do this is F#. The author of F#'s unit system wrote his PhD thesis on the subject [2], and Numbat follows the original approach in the thesis quite closely.

[1] https://github.com/sharkdp/numbat/issues/29

[2] https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-391.pdf

discuss

order

ChrisRackauckas|2 years ago

> Numbat can be compiled to Web Assembly and you can run it in your browser. I'm not sure if that is possible with Julia?

It's fine these days. https://tshort.github.io/WebAssemblyCompiler.jl/stable/examp...

I think the biggest issue with unit systems though is that algorithms are not generally unitful. I develop the Julia SciML solvers (https://docs.sciml.ai/Overview/stable/) and there's certain pieces like the initial dt calculation of an ODE solver which are not canonically correct in a unitful sense. So there's certain pieces where you have to opt out of unit checks which gets a bit messy. But other than that Unitful.jl is fine, and that's an algorithmic thing not a unit package thing.