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?
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.
Thanks so much.
I feel like the tutorial is missing something concrete along those lines.
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?
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.
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.
Aka, just giving example usage should be where we start and stop.
Last updated: Jul 05 2025 at 12:14 UTC