Hi,

the reference suggests the use of otherwise (instead of _) as the
default pattern in a case expression. While it certainly works, isn’t it
bad style, as it shadows Prelude.otherwise:

$ cat otherwise.lhs ; runhaskell otherwise.lhs 
>demo b arg = case b of
>               True      -> do print "First arg was True"
>                               let g | arg ==  "Something" = print "Got 
> something"
>                                     | otherwise           = print "Got 
> anything else"
>                               g
>               otherwise -> do print "First arg was not True"
>                               let g | arg ==  "Something" = print "Got 
> something"
>                                     | otherwise           = print "Got 
> anything else"
>                               g
>
>main = do demo True "Something"
>          demo True "Something else"
>          demo False "Something"
>          demo False "Something else"
"First arg was True"
"Got something"
"First arg was True"
"Got anything else"
"First arg was not True"
"Got something"
"First arg was not True"
otherwise.lhs: otherwise.lhs:(7,36)-(8,86): Non-exhaustive patterns in function 
g

I know that this is a contrieved example (using case on a boolean), but
in other cases you’ll get strange type errors. So while I think I did it
in the past, otherwise should be avoided in case expressions. 

Greetings,
Joachim

-- 
Joachim "nomeata" Breitner
  mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C
  JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/
  Debian Developer: [EMAIL PROTECTED]

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to