Stream: beginners

Topic: Error using the "Int" shorthand


view this post on Zulip Ashley Davis (Jun 30 2024 at 21:28):

In the Roc tutorial, in the Integers section, it says: In Roc we call these Frac and Int for short.

But when I try to use Int in my code:

x : Int
x = 3

I get the following error:

── TOO FEW TYPE ARGUMENTS in Layout.roc ────────────────────────────────────────

The Int alias expects 1 type argument, but it got 0 instead:

28  x : Int
         ^^^

Are there missing parentheses?

What am I missing?

view this post on Zulip Luke Boswell (Jun 30 2024 at 21:29):

This works

» x : Int U8
… x = 3

3 : Int U8

You are missing that the type Int a has a type variable to specify what size the integer is.

view this post on Zulip Ashley Davis (Jun 30 2024 at 21:31):

Thanks so much.

I feel like the tutorial is missing something concrete along those lines.

view this post on Zulip Luke Boswell (Jun 30 2024 at 21:33):

That's a great idea. I haven't been through the tutorial in a while.

Would you be able to make a recommendation? Where would you put this information?

view this post on Zulip Ashley Davis (Jun 30 2024 at 21:34):

Luke Boswell said:

That's a great idea. I haven't been through the tutorial in a while.

Would you be able to make a recommendation? Where would you put this information?

I think maybe just some concrete examples at the start of the "Integers" and "Fractions" sections.

view this post on Zulip Sam Mohr (Jun 30 2024 at 21:36):

That would probably be a good addition, but I don't expect it's worth explaining exactly why it works that way in the tutorial. Under the hood (source) the type of Int is Int range : Num (Integer range), so the reason it takes a type parameter is because it's a generic alias to the Num opaque type. I don't think we can explain that in a way that doesn't distract from the important bit, which is how to use it.

view this post on Zulip Sam Mohr (Jun 30 2024 at 21:36):

Aka, just giving example usage should be where we start and stop.


Last updated: Jul 05 2025 at 12:14 UTC