Hacker News new | ask | show | jobs
by cosmojg 948 days ago
Super cool! I love when programming languages try to do more with types.

Julia has a neat little library called Unitful.jl[1] which does almost exactly what Numbat does by taking advantage of Julia's extremely flexible type system. Extending it to cover all of Numbat's functionality could be trivially accomplished in a few lines. In fact, fun type magic like this is pretty much my primary motivation for using Julia in the first place.

Not that I want to detract from the author's hard work, of course, I'm just very excited about Julia! Numbat is obviously an awesome project, and I can't wait to see where it leads!

[1] https://painterqubits.github.io/Unitful.jl/stable/

1 comments

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

> 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.