Stream: beginners

Topic: print a num


view this post on Zulip JesterXL (Dec 02 2022 at 13:15):

How do I print a number? I tried dbg totalScore and got

── TYPE MISMATCH ──────────────────────────────────────────────────── main.roc 

This expect condition needs to be a Bool:

15          dbg totalScore
                 ^^^^^^^^^^

This totalScore value is a:

    Num *

But I need every expect condition to evaluate to a Booleither
Bool.true or Bool.false.

I tried the tag, too, but got:

── TYPE MISMATCH ──────────────────────────────────────────────────── main.roc 

This expect condition needs to be a Bool:

15          dbg T "the value of `totalScore` is:" totalScore
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This T tag application has the type:

    [T Str (Num *)]

But I need every expect condition to evaluate to a Booleither
Bool.true or Bool.false.

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

view this post on Zulip JesterXL (Dec 02 2022 at 13:16):

Maybe easier to just convert to a string; how do I do that?

view this post on Zulip Ayaz Hafiz (Dec 02 2022 at 13:19):

You can use “Num.toStr”, though looks like the compiler is trying to constrain the wrong type here - cc @Folkert de Vries

view this post on Zulip Folkert de Vries (Dec 02 2022 at 13:19):

hmm that should be fixed in the latest nightly I think

view this post on Zulip Folkert de Vries (Dec 02 2022 at 13:19):

it was a parsing issue, really

view this post on Zulip Luke Boswell (Dec 02 2022 at 13:21):

Can you share a snippet of how you are using dbg? It's only a new feature so could be broken. Have you seen this thread where I think a similar problem was discussed?

view this post on Zulip JesterXL (Dec 02 2022 at 13:24):

Snippet here: https://gist.github.com/JesterXL/3e8b12ae456dafce5d159983659d53e3

view this post on Zulip JesterXL (Dec 02 2022 at 13:38):

odd... if I add:

|> sumScore
    |> Num.toStr

To the end, and remove dbg, it compiles. Even as a Str, though, dbg still thinks it's supposed to be a Bool or something.

view this post on Zulip Richard Feldman (Dec 02 2022 at 13:39):

@JesterXL what does roc version print out?

view this post on Zulip JesterXL (Dec 02 2022 at 13:40):

roc nightly pre-release, built from commit d2d8511 on Thu Dec 1 09:33:35 UTC 2022

view this post on Zulip JesterXL (Dec 02 2022 at 13:41):

I'm on Mac Silicon, 12.6 Monterey

view this post on Zulip Richard Feldman (Dec 02 2022 at 14:08):

ah, that dbg issue got fixed in yesterday's nightly release :sweat_smile:

can you try downloading the latest roc binary from Releases and see if it works now?

view this post on Zulip JesterXL (Dec 02 2022 at 16:52):

OH yeah baby, that fixed, thanks y'all!


Last updated: Jul 06 2025 at 12:14 UTC