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?
I think ideally it should be a warning
like "we figured out what you meant, but you should really put a zero on there"
alternatively we could do something like how standalone tags can be considered both functions and also non-functions
actually maybe that's the best design, and then have roc format
quietly add a zero for you? :thinking:
I like the idea of having roc format add a 0
I would also be happy if .8
was just not valid syntax for a number and you always had to insert a leading zero
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?
The format would also have to be aware that (a, b) |> .1
is valid
Which circles back to Folkert's original point, I just don't know if the formatter has access to that context
it would not I think. you really need type inference
Requiring a leading digit seems to be the simplest solution
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