Stream: contributing

Topic: Roc Project Ideas


view this post on Zulip Alexander Ikonomou (Jun 09 2025 at 20:03):

I am interested in working on the project ideas Formalizing the interaction between Abilities (Typeclasses) and Defunctionalization and High-performance fixed-point operations for decimal numbers. Is one of them feasible without having worked on Roc so far?

view this post on Zulip Richard Feldman (Jun 09 2025 at 20:49):

High-performance fixed-point operations for decimal numbers definitely is!

view this post on Zulip Richard Feldman (Jun 09 2025 at 20:50):

that one can be done pretty much entirely in Zig - here is the current code: https://github.com/roc-lang/roc/blob/9cb3a3fb2b502885e95e0a3c61186cfaa3f6d0b1/src/builtins/dec.zig#L15

view this post on Zulip Richard Feldman (Jun 09 2025 at 20:50):

we're missing things like trig functions, sqrt, etc.

view this post on Zulip Richard Feldman (Jun 09 2025 at 20:51):

happy to answer any questions about it...would be amazing to have those! :heart_eyes:

view this post on Zulip Brendan Hansknecht (Jun 10 2025 at 01:33):

On top of that, what already exists likely has room for profiling and optimizations.

view this post on Zulip Alexander Ikonomou (Jun 11 2025 at 20:09):

Richard Feldman said:

happy to answer any questions about it...would be amazing to have those! :heart_eyes:

Where do I start? Do you already have any references for sqrt? I have found these libraries, dec and arithmetic.go, that seem to implement operations for decimal numbers.

dec: https://docs.rs/dec/latest/dec/index.html
arithmetic.go: https://github.com/jokruger/dec128/blob/main/arithmetic.go#L262

view this post on Zulip Anton (Jun 13 2025 at 09:53):

Hi @Alexander Ikonomou :)

Do you already have any references for sqrt?

Not that I know of.

Where do I start?

I think it would be good to get a working sqrt merged in before doing a high perf one.
So, specifically, this program should work:

app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }

import cli.Stdout
import cli.Arg exposing [Arg]

main! : List Arg => Result {} _
main! = |_args|
    four = 4dec
    sqrt = Num.sqrt(four)

    Stdout.line!(Num.to_str(sqrt))

NumSqrtUnchecked should be added here. DEC_SQRT should be added here.
And a sqrt function should be added here. Claude sonnet 4 can probably generate the sqrt function if you provide it the whole file.

view this post on Zulip Luke Boswell (Jun 13 2025 at 10:00):

It would help to clarify if this should be implemented in the new Zig compiler or the old Rust one. Richard's link above is to the new builtins in the zig compiler /src directory.

Anton's links are to the old Rust compiler.

And they are using different versions of the zig builtins implementations.

view this post on Zulip Luke Boswell (Jun 13 2025 at 10:02):

We don't have the ability to run things in the new zig compiler yet... so we'd would probably be limited to unit tests for now, or maybe hooking up the fuzzer somehow.

That being said, it may not be that far away that we have a basic interpreter working.

view this post on Zulip Anton (Jun 13 2025 at 10:19):

Anton's links are to the old Rust compiler.

Right, sorry I totally forgot to consider that

view this post on Zulip Anton (Jun 13 2025 at 10:21):

Although maybe implementing it in the old compiler is a great way to test it for now?

view this post on Zulip Anton (Jun 13 2025 at 10:25):

Do we handle things differently in the new compiler builtins compared to the old?

view this post on Zulip Luke Boswell (Jun 13 2025 at 10:31):

We will be handling things differently. We don't really have much of an implementation in the new compiler that links the Roc and Zig together. But we do have the zig builtins translated to use the same zig version as the new compiler.

view this post on Zulip Anton (Jun 13 2025 at 10:36):

Ok, yeah, so just unit tests for the new compiler sounds fine

view this post on Zulip Anton (Jun 13 2025 at 10:38):

@Alexander Ikonomou so src/builtins/dec.zig is the only file you need to make changes in. Unit tests are in that same file.

view this post on Zulip Alexander Ikonomou (Jun 23 2025 at 20:37):

Where do I start?

I think it would be good to get a working sqrt merged in before doing a high perf one.
So, specifically, this program should work:

In 7861, I added a working sqrt that just uses the sqrt from Zig. I am not sure if it is too simple.

view this post on Zulip Brendan Hansknecht (Jun 23 2025 at 22:22):

Long term we want to avoid many of the casts to and from float, but this is fine for now.


Last updated: Jul 06 2025 at 12:14 UTC