Stream: compiler development

Topic: leading digit


view this post on Zulip Folkert de Vries (Jan 28 2024 at 20:39):

should 3.4 + .8 be a valid roc expression? (issue https://github.com/roc-lang/roc/issues/5798)

now that we have tuples this is actually kind of weird. but maybe we need some custom error if a tuple accessor is used as a number?

view this post on Zulip Richard Feldman (Jan 28 2024 at 20:44):

I think ideally it should be a warning

view this post on Zulip Richard Feldman (Jan 28 2024 at 20:45):

like "we figured out what you meant, but you should really put a zero on there"

view this post on Zulip Richard Feldman (Jan 28 2024 at 20:45):

alternatively we could do something like how standalone tags can be considered both functions and also non-functions

view this post on Zulip Richard Feldman (Jan 28 2024 at 20:46):

actually maybe that's the best design, and then have roc format quietly add a zero for you? :thinking:

view this post on Zulip Isaac Van Doren (Jan 28 2024 at 21:27):

I like the idea of having roc format add a 0

view this post on Zulip Isaac Van Doren (Jan 28 2024 at 21:28):

I would also be happy if .8 was just not valid syntax for a number and you always had to insert a leading zero

view this post on Zulip Luke Boswell (Jan 28 2024 at 21:44):

I like .8 as a warning. I wonder though if there is any risk they meant to write something like a.8 or something so maybe format silently doing that would be a bad idea?

view this post on Zulip Elias Mulhall (Jan 28 2024 at 23:10):

The format would also have to be aware that (a, b) |> .1 is valid

view this post on Zulip Elias Mulhall (Jan 28 2024 at 23:11):

Which circles back to Folkert's original point, I just don't know if the formatter has access to that context

view this post on Zulip Folkert de Vries (Jan 28 2024 at 23:12):

it would not I think. you really need type inference

view this post on Zulip Anton (Jan 29 2024 at 10:28):

Requiring a leading digit seems to be the simplest solution

view this post on Zulip Brian Carroll (Jan 29 2024 at 19:18):

Right, but to expand on some of what was said above: .0 is valid syntax for a function that accesses the first element of a tuple. And .1 accesses the second element, etc.
So to generate a good error message, we need type checking. If a record access function fits at this location, we don't want to show an error about the leading 0, because that doesn't make sense. But if a fractional number fits the types , we do.


Last updated: Jul 06 2025 at 12:14 UTC