Just wanted to share the roc-units package I wrote to try and understand the Roc type system a bit better by translating some of the elm-units package.
Here's an example:
Feet, inches and centimeters are all Length
s, so they can all be added to and converted to each other.
height = Quantity.feet 5 |> Quantity.add (Quantity.inches 11)
Stdout.line! "Taylor Swift is $(height |> Quantity.toCentimeters |> Num.toStr) centimeters tall."
Taylor Swift is 180.34 centimeters tall.
But incompatible units cannot be used together.
isThisAKilometer = Quantity.kilograms 1 |> Quantity.add (Quantity.meters 1)
This 2nd argument to add has an unexpected type: ...
cc @Ian Mackenzie - check it out! :smiley:
Oh nice, didn't know you were on the Roc Zulip @Ian Mackenzie , I hope you don't mind me blatantly stealing how elm-units works :sweat_smile: it's a really elegant design
I've recently released two new versions of this package, v0.2.0 added some more US units like the teaspoon and pound-foot force (and completely rewrote how the codegen script works), and v0.3.0 added support for Roc v0.0.0-alpha2 :)
Last updated: Jul 06 2025 at 12:14 UTC