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

Joachim Breitner mail at joachim-breitner.de
Thu Nov 30 16:06:09 UTC 2017


Hi,

Am Mittwoch, den 29.11.2017, 11:04 +0100 schrieb Henning Thielemann:
> Occasionally I have multiple implementations of the same task and want to 
> choose one quickly but statically. I do not want to out-comment unused 
> branches because they shall still be type checked. So far I used this 
> scheme:
> 
>     case 0::Int of
>        0 -> putStrLn "A"
>        1 -> putStrLn "B"
>        _ -> putStrLn "C"

You can write

case id (0::Int) of 
  0 -> putStrLn "A"
  1 -> putStrLn "B"
  _ -> putStrLn "C"


instead.


> I mean, this one does not provoke any warnings:
> 
>     if True
>       then putStrLn "X"
>       else putStrLn "Y"
> 
> but is limited to two branches.

It looks like a but that it warns for Int, but not for Bool… freel free
to report that (https://ghc.haskell.org/trac/ghc/wiki/ReportABug).

Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.de
  https://www.joachim-breitner.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20171130/71dcf91f/attachment.sig>


More information about the Haskell-Cafe mailing list