Stream: beginners

Topic: How to mark a destructured field as unused?


view this post on Zulip Jared Cone (Sep 30 2024 at 05:12):

I'm trying to use record destructuring but one of the fields isn't used. Is there a way to get rid of the warning?

state is not used anywhere in your code.

11│      { state, value } = Random.rangeU32 randomState 0 10

If I replace it with _, I get this error:

I am partway through parsing a record, but I got stuck here:

 1│  app [main] {
 2│      pf: platform "../platform/main.roc",
 3│  }
 4│
 5│  import pf.Random
 6│  import pf.Stdout
 7│
 8│  main : Task {} {}
 9│  main =
10│      randomState = Random.init 0
11│      { _, value } = Random.rangeU32 randomState 0 10
         ^

TODO provide more context.

view this post on Zulip Brendan Hansknecht (Sep 30 2024 at 05:20):

You can do either of these:

{ state: _, value } = Random.rangeU32 randomState 0 10
{ value } = Random.rangeU32 randomState 0 10

view this post on Zulip Brendan Hansknecht (Sep 30 2024 at 05:20):

Obviously, the second is generally the cleaner solution, but the first is more explicit.

view this post on Zulip Jared Cone (Sep 30 2024 at 05:20):

fantastic


Last updated: Jul 06 2025 at 12:14 UTC