Stream: beginners

Topic: [List U8] vs List (Int Unsigned8)


view this post on Zulip Nick Levine (May 20 2024 at 18:34):

Hello, all. I am playing around with roc, starting with some basic Advent of Code problems. I'm using Str.walkUtf8 , and then trying to call Str.fromUtf8on a byte. I am trying to satisfy the compiler by running:

utfToS = Result.withDefault (Str.fromUtf8 (List (Num.toU8 byte))) ""

But the compiler complains that Str.fromUtf8 wants a List (Int Unsigned8), not a [List U8]. Apologies for the very basic question - what am I missing here?

view this post on Zulip Luke Boswell (May 20 2024 at 18:45):

This should work [byte] |> Str.fromUtf8 |> Result.withDefault "INVALID UTF8"

view this post on Zulip Luke Boswell (May 20 2024 at 18:46):

For example in the REPL

» ['1'] |> Str.fromUtf8 |> Result.withDefault "INVALID UTF8"

"1" : Str

view this post on Zulip Luke Boswell (May 20 2024 at 18:47):

I think with the above the List is actually being inferred as a Tag (a value) and not the builtin module.

view this post on Zulip Nick Levine (May 20 2024 at 18:47):

Luke Boswell said:

I think with the above the List is actually being inferred as a Tag (a type) and not the builtin module.

Gotcha- that worked. Thanks very much!


Last updated: Jul 06 2025 at 12:14 UTC