Stream: beginners

Topic: Difficult to understand space sensitive error


view this post on Zulip Matthieu Pizenberg (May 09 2024 at 16:04):

The following code will compile:

    Str.walkUtf8 plaintext [] \acc, letter -> acc
    |> Str.joinWith ""

while this one (added indentation) will not, with a difficult to understand error (I mean it’s simple but not easy to figure what’s wrong when not used to the operators priority of roc)

    Str.walkUtf8 plaintext [] \acc, letter -> acc
        |> Str.joinWith ""

And remark that the following one (wrong but added parenthesis) will be auto formatted to the correct version

    Str.walkUtf8 plaintext [] (\acc, letter -> acc)
        |> Str.joinWith ""

view this post on Zulip Hristo (May 09 2024 at 16:59):

If my understanding is correct, your emphasis @Matthieu Pizenberg is on the fact that your second example

Str.walkUtf8 plaintext [] \acc, letter -> acc
    |> Str.joinWith ""

is equivalent to this:

Str.walkUtf8 plaintext [] \acc, letter -> acc |> Str.joinWith ""

It's an interesting case indeed, where perhaps the error message could benefit from some augmentation with one or more suggestions for fixing.

My understanding is that formatting-wise, if there's indentation, then that is assumed to be an argument to the preceding function/token.

view this post on Zulip Matthieu Pizenberg (May 09 2024 at 17:06):

That's probably the issue indeed. I'm coming from a language where |> is an operator with low precedence (Elm) while here I guess it has higher precedence than ->, except when indented the same as the previous line? At least it an identation-sensitive error and this might be something to look for and report in the compiler I think.

view this post on Zulip Brendan Hansknecht (May 09 2024 at 19:37):

These are definitely cases we need to document and iron out

view this post on Zulip Brendan Hansknecht (May 09 2024 at 19:40):

My gut feeling is that a lambda needs a new line right after the -> or to be wrapped in parens for precedence here.

So I would think that in both cases |> on the next line should apply to the the result of Str.walkUtf8 as a whole.

view this post on Zulip Brendan Hansknecht (May 09 2024 at 19:41):

So I would expect all 3 of your original examples to be equivalent to your last example with the wrong parens


Last updated: Jul 06 2025 at 12:14 UTC