Stream: ideas

Topic: Consider changing the default integer type to I64


view this post on Zulip Francois Green (Aug 01 2024 at 22:37):

My main reason is that unsigned integers make working with indices painful .

view this post on Zulip Luke Boswell (Aug 01 2024 at 22:48):

Are you able to provide a concrete example? I think that would be helpful.

view this post on Zulip Francois Green (Aug 01 2024 at 22:51):

Here is the sort of thing I tend to bump into:
rowRange = List.range { start : At (Num.toU64((Num.toI64 row) - 1)), end : At (row + 2) }

view this post on Zulip Brendan Hansknecht (Aug 01 2024 at 23:00):

The default int type is I64. So something else must be going on here.

view this post on Zulip Brendan Hansknecht (Aug 01 2024 at 23:00):

How is row defined?

view this post on Zulip Francois Green (Aug 01 2024 at 23:04):

If I mapWithIndex over a list the index is a U64. That's the default I'm referring to. Sorry for not being more clear.

view this post on Zulip Luke Boswell (Aug 01 2024 at 23:05):

I thought it was U64 for indexes too

view this post on Zulip Luke Boswell (Aug 01 2024 at 23:05):

Yeah like

walkWithIndex :
    List elem,
    state,
    (state,
    elem,
    U64
    -> state)
    -> state

view this post on Zulip Luke Boswell (Aug 01 2024 at 23:07):

Slight aside -- why is the type annotation in the builtins for range using an underscoreList.range : _?

view this post on Zulip Luke Boswell (Aug 01 2024 at 23:09):

Francois Green said:

Here is the sort of thing I tend to bump into:
rowRange = List.range { start : At (Num.toU64((Num.toI64 row) - 1)), end : At (row + 2) }

I don't really understand the issue here, why cant you just do the maths using an U64?

» row = 1u64
… rowRange = List.range { start : At (row - 1), end : At (row + 2) }

[0, 1, 2, 3] : List U64

view this post on Zulip Brendan Hansknecht (Aug 01 2024 at 23:23):

Yes indices are U64 while the default int numeric is I64.

view this post on Zulip Francois Green (Aug 01 2024 at 23:24):

@Luke Boswell That works just fine. The weird thing is I've encountered issues where somehow the number being subtracted is seen as an I64. I just removed the extraneous code from the range and it's working like there was never a problem.

view this post on Zulip Luke Boswell (Aug 01 2024 at 23:31):

Have you seen something like this maybe?

» row = 1u64
… rowRange = List.range { start : At (row - 1i64), end : At (row + 2i64) }
This Roc code crashed with: "Hit an erroneous type when creating a layout for `4.IdentId(19)`"

── TYPE MISMATCH ───────────────────────────────────────────────────────────────

This 2nd argument to + has an unexpected type:

5│      rowRange = List.range { start : At (row - 1i64), end : At (row + 2i64) }
                                                                         ^^^^

The argument is an integer of type:

    I64

But + needs its 2nd argument to be:

    Int Unsigned64

view this post on Zulip Luke Boswell (Aug 01 2024 at 23:31):

Where your trying to subtract an I64 from a U64?

view this post on Zulip Francois Green (Aug 01 2024 at 23:35):

That seems to be the case. I'm looking back through some old advent of code solutions and I see where I've been the cause of some type mismatches.


Last updated: Jun 16 2026 at 16:19 UTC