Can I make -Wincomplete-patterns more strict?

Multi tool use
With GHC, I can enable -Wincomplete-patterns
to catch likely erroneous situations like these two.
problem1 :: Either Int String -> Int
problem1 (Left x) = x
problem2 :: Either Int String -> Int
problem2 x = case x of
Left x' -> x'
Clearly, I've forgotten to handle the Right
case in both of these functions, and GHC will tell me that. However, the compiler seems to let me off without even a warning in these two cases.
problem3 :: Either Int String -> Int
problem3 x = let Left x' = x in x'
problem4 :: Either Int String -> Int
problem4 = (Left x) -> x
I still forgot to handle a case, but GHC doesn't seem bothered. Is there a compiler flag I can set to catch situations like this where I use let
or lambda pattern matching but didn't handle all of the cases? Ideally, I want to be warned if I do something like this so I can refactor it into a case
statement or the like.
Of course, for the sake of completeness and posterity, answers relevant to other compilers are highly appreciated as well.
haskell pattern-matching warnings ghc
add a comment |
With GHC, I can enable -Wincomplete-patterns
to catch likely erroneous situations like these two.
problem1 :: Either Int String -> Int
problem1 (Left x) = x
problem2 :: Either Int String -> Int
problem2 x = case x of
Left x' -> x'
Clearly, I've forgotten to handle the Right
case in both of these functions, and GHC will tell me that. However, the compiler seems to let me off without even a warning in these two cases.
problem3 :: Either Int String -> Int
problem3 x = let Left x' = x in x'
problem4 :: Either Int String -> Int
problem4 = (Left x) -> x
I still forgot to handle a case, but GHC doesn't seem bothered. Is there a compiler flag I can set to catch situations like this where I use let
or lambda pattern matching but didn't handle all of the cases? Ideally, I want to be warned if I do something like this so I can refactor it into a case
statement or the like.
Of course, for the sake of completeness and posterity, answers relevant to other compilers are highly appreciated as well.
haskell pattern-matching warnings ghc
add a comment |
With GHC, I can enable -Wincomplete-patterns
to catch likely erroneous situations like these two.
problem1 :: Either Int String -> Int
problem1 (Left x) = x
problem2 :: Either Int String -> Int
problem2 x = case x of
Left x' -> x'
Clearly, I've forgotten to handle the Right
case in both of these functions, and GHC will tell me that. However, the compiler seems to let me off without even a warning in these two cases.
problem3 :: Either Int String -> Int
problem3 x = let Left x' = x in x'
problem4 :: Either Int String -> Int
problem4 = (Left x) -> x
I still forgot to handle a case, but GHC doesn't seem bothered. Is there a compiler flag I can set to catch situations like this where I use let
or lambda pattern matching but didn't handle all of the cases? Ideally, I want to be warned if I do something like this so I can refactor it into a case
statement or the like.
Of course, for the sake of completeness and posterity, answers relevant to other compilers are highly appreciated as well.
haskell pattern-matching warnings ghc
With GHC, I can enable -Wincomplete-patterns
to catch likely erroneous situations like these two.
problem1 :: Either Int String -> Int
problem1 (Left x) = x
problem2 :: Either Int String -> Int
problem2 x = case x of
Left x' -> x'
Clearly, I've forgotten to handle the Right
case in both of these functions, and GHC will tell me that. However, the compiler seems to let me off without even a warning in these two cases.
problem3 :: Either Int String -> Int
problem3 x = let Left x' = x in x'
problem4 :: Either Int String -> Int
problem4 = (Left x) -> x
I still forgot to handle a case, but GHC doesn't seem bothered. Is there a compiler flag I can set to catch situations like this where I use let
or lambda pattern matching but didn't handle all of the cases? Ideally, I want to be warned if I do something like this so I can refactor it into a case
statement or the like.
Of course, for the sake of completeness and posterity, answers relevant to other compilers are highly appreciated as well.
haskell pattern-matching warnings ghc
haskell pattern-matching warnings ghc
asked Dec 29 '18 at 22:14


Silvio MayoloSilvio Mayolo
14.1k22453
14.1k22453
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It seems that -Wincomplete-uni-patterns
is what you need. As someone who uses -Wall
basically all the time, I find the fact that those cases aren't covered by -Wall
or -Wincomplete-patterns
surprising and bad.
EDIT: It appears a GHC proposal to add this to -Wall
was accepted. I'm not sure the status (I checked on 8.4): https://github.com/ghc-proposals/ghc-proposals/pull/71
I do use ugly stuff like(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work onLambdaCase
? I really have no idea (it turns out-Wincomplete-patterns
is sufficient there)
– jberryman
Dec 29 '18 at 22:38
As a fellow-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!
– Silvio Mayolo
Dec 29 '18 at 22:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973738%2fcan-i-make-wincomplete-patterns-more-strict%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems that -Wincomplete-uni-patterns
is what you need. As someone who uses -Wall
basically all the time, I find the fact that those cases aren't covered by -Wall
or -Wincomplete-patterns
surprising and bad.
EDIT: It appears a GHC proposal to add this to -Wall
was accepted. I'm not sure the status (I checked on 8.4): https://github.com/ghc-proposals/ghc-proposals/pull/71
I do use ugly stuff like(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work onLambdaCase
? I really have no idea (it turns out-Wincomplete-patterns
is sufficient there)
– jberryman
Dec 29 '18 at 22:38
As a fellow-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!
– Silvio Mayolo
Dec 29 '18 at 22:40
add a comment |
It seems that -Wincomplete-uni-patterns
is what you need. As someone who uses -Wall
basically all the time, I find the fact that those cases aren't covered by -Wall
or -Wincomplete-patterns
surprising and bad.
EDIT: It appears a GHC proposal to add this to -Wall
was accepted. I'm not sure the status (I checked on 8.4): https://github.com/ghc-proposals/ghc-proposals/pull/71
I do use ugly stuff like(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work onLambdaCase
? I really have no idea (it turns out-Wincomplete-patterns
is sufficient there)
– jberryman
Dec 29 '18 at 22:38
As a fellow-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!
– Silvio Mayolo
Dec 29 '18 at 22:40
add a comment |
It seems that -Wincomplete-uni-patterns
is what you need. As someone who uses -Wall
basically all the time, I find the fact that those cases aren't covered by -Wall
or -Wincomplete-patterns
surprising and bad.
EDIT: It appears a GHC proposal to add this to -Wall
was accepted. I'm not sure the status (I checked on 8.4): https://github.com/ghc-proposals/ghc-proposals/pull/71
It seems that -Wincomplete-uni-patterns
is what you need. As someone who uses -Wall
basically all the time, I find the fact that those cases aren't covered by -Wall
or -Wincomplete-patterns
surprising and bad.
EDIT: It appears a GHC proposal to add this to -Wall
was accepted. I'm not sure the status (I checked on 8.4): https://github.com/ghc-proposals/ghc-proposals/pull/71
edited Dec 29 '18 at 22:47
answered Dec 29 '18 at 22:26
jberrymanjberryman
11.7k33471
11.7k33471
I do use ugly stuff like(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work onLambdaCase
? I really have no idea (it turns out-Wincomplete-patterns
is sufficient there)
– jberryman
Dec 29 '18 at 22:38
As a fellow-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!
– Silvio Mayolo
Dec 29 '18 at 22:40
add a comment |
I do use ugly stuff like(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work onLambdaCase
? I really have no idea (it turns out-Wincomplete-patterns
is sufficient there)
– jberryman
Dec 29 '18 at 22:38
As a fellow-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!
– Silvio Mayolo
Dec 29 '18 at 22:40
I do use ugly stuff like
(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work on LambdaCase
? I really have no idea (it turns out -Wincomplete-patterns
is sufficient there)– jberryman
Dec 29 '18 at 22:38
I do use ugly stuff like
(Left x)-> x)
in e.g. test code or throwaway scripts, but I think I'd rather disable the warning for specific files. Also how does this work on LambdaCase
? I really have no idea (it turns out -Wincomplete-patterns
is sufficient there)– jberryman
Dec 29 '18 at 22:38
As a fellow
-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!– Silvio Mayolo
Dec 29 '18 at 22:40
As a fellow
-Wall
user, I sympathize with your sadness that this check is not included. But it seems to be exactly what I'm looking for. Thanks!– Silvio Mayolo
Dec 29 '18 at 22:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973738%2fcan-i-make-wincomplete-patterns-more-strict%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
XvCxDlLZPqf5x51x5h,YGxeMdh95e,eOaOXouO,b7IzEtKCG,CRSHYMuetVZzKX4wB Wo2JURuvb1U1V3FF