Bonjour!
I want to write a program that can index into the fibonnaci number sequence, but as it turns out, they quickly get larger than even a U128. I know there aren't BigInt-s in the standard library or language for a good reason, but that begs the question, how do you recommend I make my custom version for this program to work?
I basically need a data type with lenght I can define. The two options that come to mind are Str and List(U128) with some custom definition of a function to become my + operator.
Do you see another option and what do you recommend?
Also, while I'm at it, is Dec a true decimal number or basically something like F64 ?
Thanks in advance 'x)
Hi Theo :)
Dec a true decimal number or basically something like F64 ?
Dec is a true decimal and will avoid the typical float issues.
with some custom definition of a function to become my + operator.
By the way, if you make a function named plus on your type, it will just work with +.
Do you see another option and what do you recommend?
I would recommend using a List(64) so that for addition you can convert them to U128 and the result will fit guaranteed.
Also, you'll be able to write tests for it easily, because we have special "constructors" for number literals.
You don't need to do MyBigNum.new(1). You can just do 1 if MyBigNum implements the appropriate methods. I don't know where it's discussed, but this is the first msg i have found that mentions them (it's the from digits method):
https://roc.zulipchat.com/#narrow/channel/395097-compiler-development/topic/number.20type.20inference/near/556715492
@TheoTheTorch check out https://github.com/roc-lang/roc/blob/185a692980d8d85fb06960aad25d1510cd30d450/docs/langref/numbers.md#custom-number-types
it's not merged yet but that should explain - lmk if you have questions about it!
Oh wow I am reading that right away!
You guys were not kidding about the friendly part :')
Hey, I got stuck on figuring out how I can instantiate a type I am defining. Also, I am guessing a nominal type is better for something like this than an opaque type?
Bigbig :: List(U64).{
plus = |a, _b| {
a # TODO
}
minus = |a, _b| {
a # TODO
}
from_numeral : Numeral -> Try([Bigbig, ..], [InvalidNumeral, ..])
from_numeral = |literal|
match U64.from_numeral(literal) {
Err(_) => {
Try.Err(InvalidNumeral())
}
Ok(value) => {
Try.Ok(List(value))
}
}
}
from_numaral : Numeral -> Try([List(U64), ..], [InvalidNumeral, ..])
instead of what I want it to be.
opaque is better actually!
I'd do like Bigbig :: { digits : List(U64) }.{ ... }
and from_numeral should return Try(Bigbig, ...)
Is Try.Ok() not a Try ?
Oh, you mean the Bigbig should not be inside a union.
Bigbig :: { digits : List(U64) }.{
plus = |a, _b| {
a # TODO
}
minus = |a, _b| {
a # TODO
}
from_numeral : Numeral -> Try(Bigbig, [InvalidNumeral, ..])
from_numeral = |literal|
match U64.from_numeral(literal) {
Err(_) => {
Try.Err(InvalidNumeral())
}
Ok(value) => {
Try.Ok( {digits : List(value)} )
}
}
}
I feel I've gotten closer with this x)
Oh, List literals are made like [1, 2, 3, 4], not List(1, 2, 3, 4).
This now compiles:
from_numeral = |literal|
match U64.from_numeral(literal) {
Err(_) => {
Try.Err(InvalidNumeral("ohno"))
}
Ok(value) => {
Try.Ok({ digits: [value] })
}
}
But trying to actually use this has an interesting effect:
_lol : Bigbig
_lol = 1
Segfault caught: EXCEPTION_ACCESS_VIOLATION (segfault) (code 0xC0000005)
Dev backend execution error: error.DevEvaluatorFailed
I will make an issue
In case it helps, this is the entire source related to this issue, that produces it when ran:
main! = |arg| {
_lol : Bigbig
_lol = 1
Ok({})
}
Bigbig :: { digits : List(U64) }.{
from_numeral : Numeral -> Try(Bigbig, [InvalidNumeral(Str), ..])
from_numeral = |literal|
match U64.from_numeral(literal) {
Err(_) => {
Try.Err(InvalidNumeral("ohno"))
}
Ok(value) => {
Try.Ok({ digits: [value] })
}
}
}
I'll take off to do some other things for today, but I eagerly await to be back for more Roc :)
Until then, take care everyone :)))
:croissant: :coffee: :scarf:
Can you share your OS?
I do not hit the issue on macos
Windows 11
The Segfault does not happen with the latest release so I think it's already fixed
Oh wow, I am sorry I cost you time figuring that out ':/
You are right!
Running irm https://roc-lang.org/install_roc.ps1 | iex again, I am no longer getting the segfault.
Does that always get the latest nightly release?
The script is not immediately updated after a nightly release, but it will rarely be more than 48 hours behind.
Oh wow, I am sorry I cost you time figuring that out ':/
All good :)
Last updated: Jun 16 2026 at 16:19 UTC