[Haskell-cafe] ask

Daniel Fischer daniel.is.fischer at web.de
Sun Sep 14 20:51:37 EDT 2008


Am Montag, 15. September 2008 02:24 schrieb Cetin Sert:
> Hi why do I get?

Buffering. For compiled programmes, stdin and stdout are line-buffered by 
default, so the output doesn't appear until the program finishes.
Either put
hSetBuffering stdout NoBuffering
at the top of main or, better IMO,
insert a 
hFlush stdout
into ask before the readLn.
And in eval, putStrLn would be better, I think.

HTH,
Daniel
>
> cetin at linux-d312:~/lab/exp/1> ./eq
> 23
> 23
> 3
> a = b = c = n1-0.8457820374040622n2-0.1542179625959377
>
> when I run
>
> import System.IO
>
> main :: IO ()
> main = do
>   a ← ask "a"
>   b ← ask "b"
>   c ← ask "c"
>   eval a b c
>
> ask v = do
>   putStr (v ++ " = ")
>   readLn
>
> eval a b c = do
>   case delta < 0 of
>     True  → putStr "neg"
>     False → putStr ("n1" ++ show n1 ++ "n2" ++ show n2)
>   where
>     delta = b*b - 4*c*a
>     n  o  = (-b `o` sqrt(delta))/(2*a)
>     n1    = n (+)
>     n2    = n (-)



More information about the Haskell-Cafe mailing list