Stream: beginners

Topic: How to get a Nat from U64?


view this post on Zulip Luke Boswell (Nov 06 2022 at 05:54):

I'm not sure if this is a bug. I've read through the tutorial and checked the docs; I'm pretty sure a U64 should be acceptable here where List.get requires a Nat. Am I missing something obvious?

── TYPE MISMATCH ──────────────────────────────────────────────────── day4.roc ─

This 2nd argument to get has an unexpected type:

55│                      maybeBoard = List.get state.boards boardNumber
                                                            ^^^^^^^^^^^

This boardNumber value is a:

    U64

But get needs its 2nd argument to be:

    Nat

view this post on Zulip Brendan Hansknecht (Nov 06 2022 at 07:35):

Even though a Nat could be a U64. it is not guaranteed. They are two distinct types to the roc compiler. On a 32 bit system, Nat is a U32 for example.

view this post on Zulip Brendan Hansknecht (Nov 06 2022 at 07:36):

Just need to add Num.toNat or store the number as a Nat instead of U64

view this post on Zulip Luke Boswell (Nov 06 2022 at 08:13):

Thank you. I definitely missed that. :thinking:


Last updated: Jul 06 2025 at 12:14 UTC