Stream: beginners

Topic: mapWithIndex signature is quite confusing


view this post on Zulip Sebastian Porto (Dec 06 2022 at 06:29):

I'm looking at https://www.roc-lang.org/builtins/List#mapWithIndex

I know what this does and most likely can figure out how to use it.
But I find that the function signature in the doc quite confusing

mapWithIndex : List a, a, Nat -> b -> List b

Looks like a function that takes three arguments

Which is not the case, maybe missing some parens?
Is this auto generated?

view this post on Zulip Anton (Dec 06 2022 at 06:34):

The correct type signature is mapWithIndex : List a, (a, Nat -> b) -> List b.
Thanks for bringing this to our attention @Sebastian Porto, I'll make an issue for it.

view this post on Zulip Richard Feldman (Dec 06 2022 at 06:52):

I think we already have an issue for docs generation getting parens wrong

view this post on Zulip Richard Feldman (Dec 06 2022 at 06:52):

and yeah @Sebastian Porto the docs are auto generated - in this case, incorrectly :sweat_smile:

view this post on Zulip Kevin Gillette (Dec 08 2022 at 18:19):

Ah, okay. I had thought there was just a clever right-associativity thing we were using, until I realized that most of those doc signatures are ambiguous.

I'm glad to find out it's just a doc bug. Even if it were unambiguous, I think the parens help with readability anyways.


Last updated: Jul 06 2025 at 12:14 UTC