On Fri, 2007-11-09 at 17:41 +0100, Alfonso Acosta wrote:
> I this there's no need for a binding
> 
> How about this?
> 
> import Control.Monad (when)
> import System.IO
> 
> getpasswd :: Handle -> IO String
> getpasswd h = do wasEnabled <- hGetEcho h
>                                  when  wasEnabled (hSetEcho h False)
>                                  str <- hGetLine h
>                                  when wasEnabled (hSetEcho h True)
>                                  return str

Pointless frobbing but is there any issue with setting the echo to False
when it is already False?  Otherwise not checking seems to both simpler
and quicker (not that performance matters), i.e.
getpasswd h = do
    wasEnabled <- hGetEcho h
    hSetEcho h False
    str <- hGetLine h
    hSetEcho wasEnabled
    return str

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

Reply via email to