Consider this code:
f : [Foo, True, False] -> Str
f = |x| Str.inspect(x)
expect f(Foo) == "Foo"
expect f(True) == "True"
expect f(False) == "False"
expect f(2 + 2 == 4) == "True" # Fail!
With roc test, the first three tests pass, but not the last one. I get this error:
── ✗ type mismatch ────────────────────────────────────────── /Users/ageron/dev/roc/exercism/exercism-roc/test2.roc:7:10
The first argument being passed to this function has the wrong type.
expect f(2 + 2 == 4) == "True" # Fail!
^^^^^^^^^^
This argument has the type:
Bool
But f needs the first argument to be:
[False, Foo, True]
All (3) tests passed in 130.1 ms.
I tried replacing the first line with:
f : [Foo, Bool.True, Bool.False] -> Str
but the error doesn't change.
Is there any way to make this work?
The following works, but it's not exactly what I was going for:
f : [Foo, Bool(Bool)] -> Str
f = |x| Str.inspect(x)
expect f(Foo) == "Foo"
expect f(Bool(True)) == "Bool(True)"
expect f(Bool(False)) == "Bool(False)"
expect f(Bool(2 + 2 == 4)) == "Bool(True)"
I imagine you would need something like [Foo, Other(Bool)]
But that isn't going to evaluate to "True" because you don't have a Bool
I tried replacing the first line with:
f : [Foo, Bool.True, Bool.False] -> Strbut the error doesn't change.
Bool is a closed union so it will not auto expand/merge
yeah I don't think this can really work :smile:
what's the use case?
Thanks for your answers. The use case is an exercism exercise where the user has to write a DSL to build graphs. Each node can have custom attributes whose values can be strings, integers, or booleans. I started with [Text(Str), Int(I64), Bool(Bool)], which works fine, then I though that Bool.True and Book.False are tags, so I could perhaps avoid wrapping the boolean, for simplicity. But I guess not! :sweat_smile:
Last updated: Sep 03 2026 at 15:16 UTC