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.
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:
{}
────────────────────────────────────────────────────────────────────────────────
That's smart, thanks
There are no other ways to do Anything.toString()
in runtime?
Inspect.toStr somVal
Or if you just want It debug printed dbg someVal
Neither of those Will give you any type info though
Awesome, love Roc more and more.
Thanks!
Also, I think dbg
only works with roc ...
and roc dev ...
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
Dan has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC