Hi! Me again. I sense gradual typing problem again, but am struggling to understand it and to find a better solution. Could you please explain me why the folliwing code:
is_within : BoundedInterval _, BoundedInterval _ -> Bool
is_within = |inner_interval, outer_interval|
when (normalized(inner_interval), normalized(outer_interval)) is
(_, Err(IntervalWasEmpty)) ->
Bool.false
(Err(IntervalWasEmpty), _) ->
Bool.true
(Ok((inner_first, inner_last)), Ok((outer_first, outer_last))) ->
inner_first >= outer_first and inner_last <= outer_last
Fails with the error:
── UNSAFE PATTERN in ./src/Interval.roc ────────────────────────────────────────
This when does not cover all the possibilities:
306│> when (normalized(inner_interval), normalized(outer_interval)) is
307│> (_, Err(IntervalWasEmpty)) ->
308│> Bool.false
309│>
310│> (Err(IntervalWasEmpty), _) ->
311│> Bool.true
312│>
313│> (Ok((inner_first, inner_last)), Ok((outer_first, outer_last))) ->
314│> inner_first >= outer_first and inner_last <= outer_last
Other possibilities include:
( Ok _, Err _ )
( Ok _, Ok _ )
I would have to crash if I saw one of those! Add branches for them!
Even though I clearly covered these possibilities.
Here is definition of the normalized
function:
normalized : BoundedInterval a -> Result (Int a, Int a) [IntervalWasEmpty]
This is indeed a bug with tuples #5530
Oh, ok. Thanks for the info.
Last updated: Jul 06 2025 at 12:14 UTC