Stream: beginners

Topic: ✔ Reading a file as string


view this post on Zulip Vladimir Zotov (Aug 02 2024 at 09:22):

I have this compiler error. Does anyone know what's wrong?

TYPE MISMATCH

This 1st argument to `readUtf8` has an unexpected type:

22│      File.readUtf8! (Path.fromStr "yarn.lock")
                         ^^^^^^^^^^^^^^^^^^^^^^^^

This `Path.fromStr` call produces:

    InternalPath.InternalPath

But `readUtf8` needs its 1st argument to be:

    Str

view this post on Zulip Hannes (Aug 02 2024 at 09:28):

It's because the File.readUtf8 function takes a path as a Str, to use a Path as the path, you can use the Path.readUtf8 function

view this post on Zulip Hannes (Aug 02 2024 at 09:30):

The docs for the File module have a link on each function to the other version of it that takes a Pathand vice versa

view this post on Zulip Vladimir Zotov (Aug 02 2024 at 09:41):

I get the problem, but why do docs also give this example if it can never compile?

image.png

view this post on Zulip Sam Mohr (Aug 02 2024 at 10:24):

Unlike Rust, we don't (yet) test our doc code examples. That would be a good thing to do in the future!

view this post on Zulip Anton (Aug 02 2024 at 10:51):

This PR fixes the outdated example

view this post on Zulip batyoullfly (Aug 02 2024 at 18:48):

Sam Mohr said:

Unlike Rust, we don't (yet) test our doc code examples. That would be a good thing to do in the future!

How involved would this be? Could you just find all code blocks in the docs and run their contents through roc check or would it be more complicated than that?

view this post on Zulip Notification Bot (Aug 03 2024 at 06:27):

Vladimir Zotov has marked this topic as resolved.

view this post on Zulip Anton (Aug 03 2024 at 09:41):

How involved would this be? Could you just find all code blocks in the docs and run their contents through roc check or would it be more complicated than that?

Examples may be missing imports and an app header but yeah should be pretty straightforward


Last updated: Jul 06 2025 at 12:14 UTC