Stream: beginners

Topic: ✔ Best way to introspect (debug) Roc programs


view this post on Zulip Dan (Jan 09 2024 at 23:24):

Is there any way to debug my Roc programs until I will start understanding them properly?

Currently I would love to have something like

log(typeof (EXPRESSION))

so Roc compiler/runtime will show me some info about expression or variable (like in REPL).
Or what are the workaround/advices?

Thanks.

view this post on Zulip Agus Zubiaga (Jan 09 2024 at 23:37):

You can make a def and give it any type annotation:

whatIsThis : {}
whatIsThis = { x : 32, y : "hello" }

Then the compiler will print the inferred type when it finds the mismatch:

── TYPE MISMATCH ──────────────────────────────────────────────────── Test.roc ─

Something is off with the body of the whatIsThis definition:

3│  whatIsThis : {}
4│  whatIsThis = { x : 32, y : "hello" }
                 ^^^^^^^^^^^^^^^^^^^^^^^

The body is a record of type:

    {
        x : Num *,
        y : Str,
    }

But the type annotation on whatIsThis says it should be:

    {}


────────────────────────────────────────────────────────────────────────────────

view this post on Zulip Dan (Jan 09 2024 at 23:37):

That's smart, thanks

view this post on Zulip Dan (Jan 09 2024 at 23:50):

There are no other ways to do Anything.toString() in runtime?

view this post on Zulip Brendan Hansknecht (Jan 09 2024 at 23:52):

Inspect.toStr somVal

view this post on Zulip Brendan Hansknecht (Jan 09 2024 at 23:52):

Or if you just want It debug printed dbg someVal

view this post on Zulip Brendan Hansknecht (Jan 09 2024 at 23:53):

Neither of those Will give you any type info though

view this post on Zulip Dan (Jan 09 2024 at 23:53):

Awesome, love Roc more and more.

Thanks!

view this post on Zulip Brendan Hansknecht (Jan 09 2024 at 23:53):

Also, I think dbg only works with roc ... and roc dev ...

view this post on Zulip Luke Boswell (Jan 10 2024 at 02:28):

If you use the language server (I'm using VS Code) you can also hover to get the type information
Screenshot-2024-01-10-at-13.28.10.png

view this post on Zulip Notification Bot (Jan 10 2024 at 09:42):

Dan has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC