[Haskell-cafe] out-commented code vs. case with redundant pattern matches

Henning Thielemann lemming at henning-thielemann.de
Wed Nov 29 11:03:57 UTC 2017

On Wed, 29 Nov 2017, Sergiu Ivanov wrote:

> Hi Henning,
> Maybe you can factor out the implementations of different branches into
> separate functions, like in:
>  case 0 :: Int of
>    0 -> putStrLn "A"
>    1 -> handleOne1
>  where
>    handleOne1 :: Int -> IO ()
>    handleOne1 = putStrLn "B"
>    handleOne1 :: Int -> IO ()
>    handleOne2 = putStrLn "C"

I had something similar in mind and found it too complicated. I could also 
omit 'case' completely, and directly call handleOne1 and prefix unused 
handleOne's with an underscore. Maybe it is the best I can do for now.

> To me, you are creating overlapping patterns in the case statements, so
> having unused branches and _not_ having warnings about them kind of
> breaks the point of this type of warning (personal opinion).

Not quite. We can silence "unused" warnings for variables by prepending an 
underscore. Something similar might work for case patterns.

More information about the Haskell-Cafe mailing list