Stream: beginners

Topic: Type variables implement two abilities?


view this post on Zulip Ian McLerran (Jan 21 2024 at 17:38):

Is there any way for a type variable to implement two abilities?

I had code where I had declared a type alias:

Node a : [Data { val : a, idx : Nat }, Null] where a implements Inspect.Inspect
Tree a : List (Node a) where a implements Inpsect.Inspect

I also have defined a function which required my Tree a to implement Eq for a, so I typed my function:

isLeafSimilar : Tree a, Tree a -> Bool where a implements Eq

Adding Inspect to my Tree a alias caused a compiler crash:

thread '<unnamed>' panicked at 'list element is error type', crates/compiler/mono/src/ir.rs:4854:50
stack backtrace: ...

Removing the requirement for a to implement Inspect, which was previously added for debugging purposes fixed this crash. If possible however, I would like to be able to add both of these abilities directly to my Tree alias, however I can't seem to find any syntax which will allow me to add two abilities to a in my Tree alias declaration. Is there any way to add multiple abilities to a type variable?

view this post on Zulip Brendan Hansknecht (Jan 21 2024 at 18:06):

I think it is just a implements Inspect.Inspect, Eq, Etc

view this post on Zulip Ian McLerran (Jan 21 2024 at 20:39):

Ah, I found it! The correct syntax is where a implements Inspect.Inspect & Eq

view this post on Zulip Richard Feldman (Jan 21 2024 at 20:55):

does it have to be qualified as Inspect.Inspect or does Inspect work on its own?

view this post on Zulip Ian McLerran (Jan 21 2024 at 20:58):

Actually, no, it does not. However I believe the error message that told me I needed to implement Inspect to use dbg specified the qualified version.

view this post on Zulip Ian McLerran (Jan 21 2024 at 21:00):

I'm planning to file an issue for my original question, since a compiler crash with

thread '<unnamed>' panicked at 'list element is error type', crates/compiler/mono/src/ir.rs:4854:50
stack backtrace: ...

was very unhelpful in identifying my the cause of the failure to compile.

view this post on Zulip Richard Feldman (Jan 21 2024 at 21:13):

thanks!

view this post on Zulip Ian McLerran (Jan 22 2024 at 00:17):

I'm trying to find the most generic reproduction of this compiler crash as possible, however thus far, I have not been able to generate this crash outside of my specific code sample. If I change my type alias and function type in my original code to use the two different abilities, I can still reproduce the crash. However, in a trivial roc program where I have tried to reproduce the structure (not functionality) of the code which caused the crash, I have not yet been able to do so.

Should I file an issue with a link to a repo containing the code which will produce the crash, or wait to file until I can abstract the issue more?

view this post on Zulip Brian Carroll (Jan 22 2024 at 08:05):

I'd say create the issue then update it as you get more info, an improved reproduction, etc.


Last updated: Jul 05 2025 at 12:14 UTC