Stream: contributing

Topic: Optional record fields


view this post on Zulip Elias Mulhall (Oct 25 2023 at 03:51):

I've been playing with optional record fields and I've come across some bugs. I made a gist https://gist.github.com/mulias/f0c16172fc699439da4f210b19002f97#file-main-roc

One thing I wanted to test is this note from the tutorial

This is also the type that would have been inferred for table if no annotation had been written. Roc's compiler can tell from the destructuring syntax title ? "" that title is an optional field, and that it has the type Str. These default values can reference other expressions in the record destructure; if you wanted, you could write { height, width, title ? "", description ? Str.concat "A table called " title }.

What I've found is that

One of the examples uses the Array2D module that I've been working on. I included the whole module, but most of it isn't needed. The important part is that the walk function tries to do this

WalkOptions : {
    direction ? [Forward, Backwards],
    orientation ? [Rows, Cols],
    start ? Index,
}

walk : Array2D a, state, WalkOptions, (state, a, Index -> state) -> state
walk = \array, startState, options, fn ->
    { direction ? Forward, orientation ? Rows, start ? walkStart array direction } = options

This causes the LLVM error example in main.roc. If you change it to

WalkOptions : {
    direction ? [Forward, Backwards],
    orientation ? [Rows, Cols],
    start ? Index,
}

walk : Array2D a, state, WalkOptions, (state, a, Index -> state) -> state
walk = \array, startState, options, fn ->
    { direction ? Forward, orientation ? Rows, start ? {x: 0, y: 0}  } = options

then the example works fine.

So, all that said, how challenging would it be to start digging in to some of these issues? Is it reasonable for me to start looking into the UNRECOGNIZED NAME error for cases where the code runs fine? Or is that still pretty ambitious?

view this post on Zulip Elias Mulhall (Oct 25 2023 at 04:04):

Oh, or the binary operator desugaring error. If you use an if,+, etc in the default value that fails with a compiler bug message.

view this post on Zulip Anton (Oct 25 2023 at 10:21):

It's not my area of expertise but the simple UNRECOGNIZED NAME errors seem doable. I recommend the cursor.so editor to assist you.


Last updated: Jul 06 2025 at 12:14 UTC