Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  different getChar behaviour in interpeter and    compiled
      program (Motiejus Jak?tys)
   2. Re:  different getChar behaviour in interpeter and compiled
      program (Brandon Allbery)
   3. Re:  different getChar behaviour in interpeter and compiled
      program (Motiejus Jak?tys)


----------------------------------------------------------------------

Message: 1
Date: Sun, 14 Oct 2012 17:14:31 +0200
From: Motiejus Jak?tys <[email protected]>
Subject: [Haskell-beginners] different getChar behaviour in interpeter
        and     compiled program
To: [email protected]
Message-ID: <20121014151252.GA7633@precise>
Content-Type: text/plain; charset=us-ascii

Hi,

consider this program:

    main = do
        c <- getChar
        putStrLn ("Entered: " ++ [c])
        main

(It reads a character and prints it out, for ever).

When invoked from interpreter:

    motiejus@precise> ghci
    GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package integer-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Prelude> :load getchar.hs
    [1 of 1] Compiling Main             ( getchar.hs, interpreted )
    Ok, modules loaded: Main.
    *Main> main
    lEntered: l
    aEntered: a

The behaviour is fine: right after entering a character, I get echo
back.

However, when started with runhaskell (or compiled ./getchar):

    motiejus@precise> runhaskell getchar.hs
    la<CR>
    Entered: l
    Entered: a
    Entered:

Behaviour is different: I entered "l", but did not get the "entered"
back. Only after I entered carriage-return, I got my multiple echos
(including the CR).

Why is it so? Is it possible to make Haskell read character-by-character
in a compiled program?

Clarification: behaviour of
    $ runhaskell ./getchar.hs
is the same as 
    $ ghc ./getchar.hs && ./getchar

Ubuntu 12.04.1 i386, Haskell from standard repositories 7.4.1-1ubuntu2.

Regards,
Motiejus



------------------------------

Message: 2
Date: Sun, 14 Oct 2012 11:31:58 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] different getChar behaviour in
        interpeter and compiled program
To: Motiejus Jak?tys <[email protected]>
Cc: [email protected]
Message-ID:
        <cakfcl4wclpk+a2sn+2w9uvzzkdu_j8pjadojo0bewqzrbha...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sun, Oct 14, 2012 at 11:14 AM, Motiejus Jak?tys <[email protected]>wrote:

> The behaviour is fine: right after entering a character, I get echo
> back.
>
> However, when started with runhaskell (or compiled ./getchar):
>
>     motiejus@precise> runhaskell getchar.hs
>     la<CR>
>     Entered: l
>     Entered: a
>     Entered:
>

http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-faq.htmlscroll
to the bottom.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix/linux, openafs, kerberos, infrastructure          http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121014/656d6783/attachment-0001.htm>

------------------------------

Message: 3
Date: Sun, 14 Oct 2012 18:00:42 +0200
From: Motiejus Jak?tys <[email protected]>
Subject: Re: [Haskell-beginners] different getChar behaviour in
        interpeter and compiled program
To: Brandon Allbery <[email protected]>
Cc: [email protected]
Message-ID: <20121014160042.GA4008@precise>
Content-Type: text/plain; charset=utf-8

On Sun, Oct 14, 2012 at 11:31:58AM -0400, Brandon Allbery wrote:
> On Sun, Oct 14, 2012 at 11:14 AM, Motiejus Jak?tys 
> <[email protected]>wrote:
> 
> > The behaviour is fine: right after entering a character, I get echo
> > back.
> >
> > However, when started with runhaskell (or compiled ./getchar):
> >
> >     motiejus@precise> runhaskell getchar.hs
> >     la<CR>
> >     Entered: l
> >     Entered: a
> >     Entered:
> >
> 
> http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-faq.htmlscroll
> to the bottom.
> 

Thanks.

Not exactly like in the FAQ, but it lead me to the right direction. In
my case stdin in ghci is not buffered, whereas in ghc it is line
buffered. Turning stdin buffering off before getChar (hSetBuffering
stdin NoBuffering) made it work.

Regards,
Motiejus



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 52, Issue 20
*****************************************

Reply via email to