[Haskell-cafe] Disable echo in POSIX terminal

Derek Elkins derek.a.elkins at gmail.com
Fri Nov 9 16:37:20 EST 2007


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



More information about the Haskell-Cafe mailing list