Is this a bug? This example works:
collatzConjecture = \number ->
when (number % 2) is
0 -> (number // 2)
_ -> (3 * number + 1)
but when using Bool, I get the following error
collatzConjecture = \number ->
when (Num.isEven number) is
Bool.true -> (number // 2)
_ -> (3 * number + 1)
This pattern is malformed
16│ Bool.true -> (number // 2)
^^^^^^^^^
Full code
module [steps]
steps : U64 -> Result U64 _
steps = \number ->
when number is
0 -> Err "Input must be greater than 0"
_ -> Ok (step number 0)
step = \number, count ->
when number is
1 -> count
_ -> number |> collatzConjecture |> step (count + 1)
collatzConjecture = \number ->
when (Num.isEven number) is
Bool.true -> (number // 2)
_ -> (3 * number + 1)
If I remember correctly, pattern matching with bools doesn’t work at the moment
Hm, I would think a Bool type would just be a tag union of [ True | False ]
yeah, it used to be - we changed it based on #ideas > opaque bools although #ideas > custom types would change it so that True
and False
would both have the type Bool
and could be used in pattern matching
OMG, yes please to the custom types proposal!
:smiley: want to drop a comment in the #ideas > custom types thread?
Last updated: Jul 06 2025 at 12:14 UTC