[Haskell-cafe] Re: Re: Read a single char

Hans van Thiel hthiel.char at zonnet.nl
Wed Oct 25 12:57:38 EDT 2006

On Tue, Oct 24, 2006 at 06:14:14PM +0200, Hans van Thiel wrote:
        > I have a similar question. When I use getChar with Hugs the
        > (caused by pressing 'Enter')  seems to be carried over into
        the next
        > call of main, where it is treated as a single input
        > The workaround is getLine and head, but it would be nice to
        drop the
        > newline right away. I suppose the solution offered here: 
        >>that is the correct behavior, input is never discarded, it is
        just >>saved
        >>up until you press enter for the first time. if you type
        >>your next four getChars will get 'f' 'o' 'o' and '\n'. it is
        not >>haskell
        >>that is treating enter as specially, it is your terminal,
        getChar >>just returns exactly what was passed to it.
        Yes, but the problem is with two subsequent runs of main. I'd
        have thought the buffer would flush automatically and the second
        run would start with an empty buffer. Now I enter 'b', then
        press 'Enter' and it works as expected. Then I 'main' again, and
        it terminates right away with a blank line. If I enter 'a', 'b'
        and then Enter, the second run takes the second character.
        If I'm not doing anything wrong (always a possibility :-), then
        it seems more like a (small) bug in Hugs, as Neil suggested. 
        I'll have to check what chgi does.
        John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list