New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pattern guards give false exhaustivity errors #2795
Comments
x :: X -> Int
x y = case y of
Y -> 0
_ -> let
k _ = case y of
X n | otherwise -> 2
in case y of
X n -> case n of -- guard 1 <- n
1 -> 1
_ -> k true
We scrutinize |
Lets see if I can come up with something better. btw. I know its a bad excuse but in this example you can change the order of matches to: x :: X -> Int
x = case _ of
X n | 1 <- n -> 1
| otherwise -> 2
Y -> 0 and it works. |
I think the transformation is right, the exhaustivity checker just doesn't know that in subsequent matches missing cases can be ruled out. We have different alternatives I guess:
btw. Are there any written down notes on invariants of case expressions in surface language? |
Thanks for looking at this. If it's possible to move the transformation after linting and/or type-checking, I think that would be the way to go. |
I am still having this problem on 0.11.2. Code: head :: forall a. Stream a -> a
head xs | Cons x _ <- step xs = x error:
|
Oh boy, I should have more and better tests.
This time it's the exhaustiveness checker at [1]. It checks for irrefutable
binders which by definition [2] doesn't look into the structure of the data
type. We need to take a look into the definition of the data type and check
if its a product type, and if constructor binders are exhaustive.
[1]
https://github.com/purescript/purescript/blob/master/src/Language/PureScript/Linter/Exhaustive.hs#L206
[2]
https://github.com/purescript/purescript/blob/0ee5b7495fae6319ca6f33a6691cf6cae1110466/src/Language/PureScript/AST/Binders.hs#L85
.
Matthew Leon <notifications@github.com> schrieb am Mo., 3. Apr. 2017 um
18:19 Uhr:
… I am still having this problem on 0.11.2.
Code:
head :: forall a. Stream a -> a
head xs | Cons x _ <- step xs = x
error:
in module Main
at src/Main.purs line 35, column 1 - line 35, column 33
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 applying a function __unused
of type Partial => t1 -> t1
to argument case xs of
xs | Cons x _ <- step xs -> x
while checking that expression __unused (case xs of
xs | Cons x _ <- step xs -> x
)
has type a0
in value declaration head
where a0 is a rigid type variable
bound at line 35, column 1 - line 35, column 33
t1 is an unknown type
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2795 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AByiia_jdPVyBO2cAZlKCMG3JGbiKxUmks5rsRv_gaJpZM4MtxRQ>
.
|
Let's open a new issue for this one. |
Example:
which gives:
It looks like the desugaring is at fault here, since
X n
is the only alternative left after things are expanded.@alexbiehl Any ideas here?
The text was updated successfully, but these errors were encountered: