Stream: beginners

Topic: feedback on custom numbers in language reference


view this post on Zulip Richard Feldman (Feb 03 2026 at 17:37):

I wrote up a draft explanation of how custom numbers work in the new compiler: https://gist.github.com/rtfeldman/f4f1ee9b0c8194e2e3d7309059bef7a4

the idea is for this to end up in the language reference.

any feedback welcome!

view this post on Zulip Anton (Feb 03 2026 at 18:23):

Reads well :)

view this post on Zulip Anton (Feb 03 2026 at 18:23):

I assume going with Ratio over Fraction was a deliberate choice?

view this post on Zulip Anton (Feb 03 2026 at 18:24):

In my opinion you can cut " which would be the requirement if div assumed both arguments had the same type (like they happen to in number types like Ratio and Dec, but not in number types like Duration)."

view this post on Zulip Richard Feldman (Feb 03 2026 at 18:49):

Anton said:

I assume going with Ratio over Fraction was a deliberate choice?

yeah that's what Clojure calls it

view this post on Zulip Richard Feldman (Feb 03 2026 at 18:50):

Anton said:

In my opinion you can cut " which would be the requirement if div assumed both arguments had the same type (like they happen to in number types like Ratio and Dec, but not in number types like Duration)."

fair, although I wanted to call that out because it's how all the builtin number types happen to be shaped, so I wanted to be clear that it's an intentional decision not to be that restrictive

view this post on Zulip Luke Boswell (Feb 03 2026 at 19:06):

I'm hyped for custom numbers! One of the first things I want to try out is making a 2D Projective Geometric Algebra number type for making really fast and precise physics calculations. I've got this idea that it would be cool if the graphics platform and associated packages for making games just used a nicer mathematical primitive rather than forcing game devs to think in terms of the lower level abstractions like how they efficiently represents vectors.

view this post on Zulip Luke Boswell (Feb 03 2026 at 19:07):

This idea may not go anywhere... but from the YT rabbit holes I've been down I'm feeling hopeful it will be nicer to work with.

view this post on Zulip Anton (Feb 03 2026 at 19:11):

This looks really neat by the way:

duration : Duration
duration = 5.Min + 30.Sec

Maybe that should be higher up as a hook for the reader :p

view this post on Zulip Richard Feldman (Feb 03 2026 at 19:37):

yeah maybe could note some things up top that you can do with it

view this post on Zulip Richard Feldman (Feb 03 2026 at 19:37):

and then explain how they all work

view this post on Zulip Luke Boswell (Feb 03 2026 at 20:13):

I love a good TLDR or Exec Summary :smiley:

view this post on Zulip Norbert Hajagos (Feb 04 2026 at 18:06):

Very exciting to read! Have you thought about using Tags for telling the negativeness? The is_negative associated functions is very clear, just that looking at this line, I need the line above it to know what the first parameter should be: Numeral.init(False, [], numeral.digits_after_pt()). Maybe init could accept the [NonNegative, Negative] tag union?
I know my comment's mostly about looks. The semantics are awesome and powerful!

view this post on Zulip Rick Hull (Feb 04 2026 at 22:28):

I gotta question: can this be used for "tagging units" like metric stuff in a physics sim? I've never found an ergonomic solution; does Roc have something else that already works well? maybe tagged unions somehow?

view this post on Zulip Luke Boswell (Feb 04 2026 at 22:29):

Yeah the metric stuff is one of the main motivations that led to this design, like 12.Meters or 43.Psi

view this post on Zulip Rick Hull (Feb 04 2026 at 22:30):

new question: does octopus mean roughly "awesome!" because that's what it means to me

view this post on Zulip Rick Hull (Feb 04 2026 at 22:31):

what's the 2nd best way to do units (e.g. metric) in roc, using old features?

view this post on Zulip Hannes (Feb 05 2026 at 12:01):

Rick Hull said:

what's the 2nd best way to do units (e.g. metric) in roc, using old features?

I made a port of elm-units a while ago: roc-units

view this post on Zulip Hannes (Feb 05 2026 at 12:14):

I'm excited to port it to use custom numbers when the new compiler is ready :grinning_face_with_smiling_eyes:

view this post on Zulip Rick Hull (Feb 05 2026 at 18:01):

Looks great! I love this style of implementation, mostly declarative and definitional, and obviously correct, with really nice things falling out of it. I'm not a license nerd, nor do I want to be, but I'd be tempted to reword "partly based on" to "inspired by". :+1:

view this post on Zulip Lukas Juhrich (Feb 06 2026 at 09:00):

To give some outside perspective on the 5.Sec + 3.Min API: in the latest C# version (14, released last year) this is also possible using extension members, where one can write 5d.Sec. Of course, this is evaluated at runtime, so not quite as cool :)
There is even a quite popular package which does this: https://github.com/angularsen/UnitsNet?tab=readme-ov-file#extension-packages

To me, it is cool to see how similar ideas for ergonomic APIs emerge in different contexts.

view this post on Zulip Hannes (Feb 07 2026 at 11:18):

Rick Hull said:

I'm not a license nerd, nor do I want to be, but I'd be tempted to reword "partly based on" to "inspired by". :+1:

I believe the BSD 3 clause licence is one of the most permissive licences, if you make a derivative work then it only requires you to include a copy of the original licence with your derivative and to not imply that the original project endorses your derivative. I included a copy of the original licence and I think the names are different enough to not confuse anyone.

If thousands of companies are allowed to include BSD licenced code verbatim in their proprietary projects then I think I'll be okay translating a BSD licenced codebase and re-licencing it :sweat_smile:


Last updated: Feb 20 2026 at 12:27 UTC