I was trying to re-implement Data.List.range as an exercise, but it didn’t work out as hoped:
rangeMine :: Int -> Int -> List Int
rangeMine start end
| start == end = start : Nil
| start < end = start : rangeMine (start + 1) end
| start > end = start : rangeMine (start - 1) end
This results in the following error:
A case expression could not be determined to cover all inputs.
The following additional cases are required to cover all inputs:_ _
Alternatively, add a
Partial
constraint to the type of the enclosing value.while checking that type
Partial => t0
is at least as general as typeList Int
while checking that expressioncase start end of start end | (eq start) end -> (Cons start) Nil | (lessThan start) end -> (Cons start) ((...) end) | (greaterThan start) end -> (Cons start) ((...) end)
has type
List Int
in binding grouprangeMine
where
t0
is an unknown typeSee https://github.com/purescript/documentation/blob/master/errors/NoInstanceFound.md for more information, or to contribute content related to this error.
The first part of the error message clear: the guard cases are not exhaustive; when I replace start > end
with otherwise
, it does work. (Unfortunately, I’m unable to decipher the error message right below “add a Partial
constraint” yet…)
If start
and end
are Int
s and I covered the “lower than”, “greater than”, and “equal” cases, what case(s) did I miss?