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.fromUtf8
on 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?
This should work [byte] |> Str.fromUtf8 |> Result.withDefault "INVALID UTF8"
For example in the REPL
» ['1'] |> Str.fromUtf8 |> Result.withDefault "INVALID UTF8"
"1" : Str
I think with the above the List
is actually being inferred as a Tag (a value) and not the builtin module.
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