Stream: beginners

Topic: Path Eq in basic web server


view this post on Zulip Trevor Settles (May 31 2024 at 21:21):

I noticed that Path doesn't implement Eq, but the isEq function is commented out. This kind of thing would be helpful for testing, but it looks like this choice has been made on purpose. I'm just curious of the reasoning here, as I couldn't find out why

view this post on Zulip Luke Boswell (May 31 2024 at 23:04):

I'm not aware of any reason. Maybe it's just because they need to be canonicalised somehow so we can compare e.g. from OsStr or from a user provided Str. I don't see why we couldn't just auto derive it.

This is probably a @Richard Feldman question I think.

view this post on Zulip Brendan Hansknecht (Jun 01 2024 at 00:01):

Yeah, would be great to enable eq, but iirc, you have to be careful. generic conanicalization of paths is tricky to get right. It might even require os calls to be correct (due to symlinks and the like). As such, it may not be possible in pure roc.

view this post on Zulip Trevor Settles (Jun 01 2024 at 03:29):

Yeah, I found the commit/PR where that got added. It looks like it was never in the codebase uncommented. It uses Str.isEqUtf8 which ins't currently in the builtins, so that'd be my guess as to why its commented out

view this post on Zulip Brendan Hansknecht (Jun 01 2024 at 03:36):

Is a path a string or a list U8?

view this post on Zulip Trevor Settles (Jun 01 2024 at 18:13):

It looks like both. One variant is Str, while the other two are bytes.

Also, for connivence, heres a link to the related code

https://github.com/roc-lang/basic-webserver/commit/9e91ea20297b65bca0f0d1b760cac4cb591c5818#diff-410d2c23ece098b0549b91ce436debc8c082198dd95dd8fa5fa2dc3ceab3e561R125-R141

view this post on Zulip Brendan Hansknecht (Jun 01 2024 at 18:41):

Personally, I would suggest that for now you simply add a naiveEq method or something similar. Then make it just do Str.toUtf8 for the strings. Then use == on the underlying bytes.

view this post on Zulip Brendan Hansknecht (Jun 01 2024 at 18:41):

It can obviously be expanded in various ways, but I think it is a good starter.


Last updated: Jul 05 2025 at 12:14 UTC