Stream: ideas

Topic: anyhow like errors


view this post on Zulip Brendan Hansknecht (May 18 2023 at 18:19):

Maybe this doesn't apply to a language like roc, but I thought this might be an interesting discussion.

In Rust, it is quite common for projects to use error handling crates like anyhow. Anyhow enables fundamentally keeping around the original error type while adding extra context.

Given these projects are so common, it suggests there is a want for this kind of feature. Would we expect the same to come up in Roc? How would we expect it to be handled? Just adding wrapper tags with pattern matching to generate output strings?

Just kinda wondering if we will have a similar gap in extra information users would want with errors.

Any thoughts?

view this post on Zulip Ayaz Hafiz (May 18 2023 at 18:21):

I think it will be inevitable (a similar thing occurs in go where you want to accumulate context). I do think however the lightweight feel of Roc's tag unions will make it much easier to construct and use those wrapper variants. Personally I think we should see the behavior in practice before trying to optimize

view this post on Zulip Brendan Hansknecht (May 18 2023 at 18:45):

Sure, but if it is expected and an area that isn't addressed well by core languages in many cases, we may want to think about it some.

view this post on Zulip Qqwy / Marten (May 21 2023 at 19:20):

There is this really interesting article about the disadvantages of Result-based error handling and how to improve it: https://www.parsonsmatt.org/2018/11/03/trouble_with_typed_errors.html

view this post on Zulip Qqwy / Marten (May 21 2023 at 19:23):

This gave rise to the Plucky library in Haskell
and to the 'Veither' and ExceptV/VexceptT libraries/abstractions in PureScript.

view this post on Zulip Qqwy / Marten (May 21 2023 at 19:29):

I think those ideas are very closely related to what is possible with Roc's tag unions, so it might be a match made in heaven

view this post on Zulip Brendan Hansknecht (May 21 2023 at 19:35):

A lot of it looks like just being able to use open tags and merge tags.

view this post on Zulip Richard Feldman (May 21 2023 at 22:42):

oh, this is the article that inspired tag unions! You found it! :smiley:

view this post on Zulip Richard Feldman (May 21 2023 at 22:42):

years later I kept looking for this and always failed to find it :laughing:

view this post on Zulip Richard Feldman (May 21 2023 at 22:42):

this sentence from the article specifically:

In PureScript or OCaml, you can use open variant types to do this flawlessly. Haskell doesn’t have open variants, and the attempts to mock them end up quite clumsy to use in practice.

view this post on Zulip Richard Feldman (May 21 2023 at 22:43):

I was like "wait hang on, how does that work?" and then went off on a tangent trying to prototype error handling in OCaml using only polymorphic variants

view this post on Zulip Richard Feldman (May 21 2023 at 22:44):

and it turned out it worked really nicely!


Last updated: Jun 16 2026 at 16:19 UTC