
Hi why do I get? cetin@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 (-)

On 2008 Sep 14, at 20:24, Cetin Sert wrote:
Hi why do I get?
cetin@linux-d312:~/lab/exp/1> ./eq 23 23 3 a = b = c = n1-0.8457820374040622n2-0.1542179625959377
As is typical for Unix, filehandles including standard input and standard output are line buffered. See hSetBuffering ( http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#v%... ). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

On 2008 Sep 14, at 20:47, Brandon S. Allbery KF8NH wrote:
On 2008 Sep 14, at 20:24, Cetin Sert wrote:
Hi why do I get?
cetin@linux-d312:~/lab/exp/1> ./eq 23 23 3 a = b = c = n1-0.8457820374040622n2-0.1542179625959377
As is typical for Unix, filehandles including standard input and standard output are line buffered. See hSetBuffering ( http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#v%... ).
Also, looking at that path, I'm tempted to point you to http://www.haskell.org/haskellwiki/Homework_help . -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

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@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 (-)

Hello, If we look at these two examples, it appears that the results are reversed: Prelude> let n o = (-1 `o` 1) in n (-) 0 Prelude> let n o = (-1 `o` 1) in n (+) -2 Prelude> we expect (-1 - 1) = -2 and (-1 + 1) = 0, but we get the opposite. Due to operator precedence, the equations are being interpreted as: Prelude> let n o = (-(1 `o` 1)) in n (-) 0 Prelude> let n o = (-(1 `o` 1)) in n (+) -2 The fix is to use parens around a negative term: Prelude> let n o = ((-1) `o` 1) in n (-) -2 Prelude> let n o = ((-1) `o` 1) in n (+) 0 Prelude> I have heard complaints about the negation sign in Haskell before, I suppose this is why. Hopefully someone else can provide more details. j. ps. You could probably also fix it by changing the precedence of the `o` operator. I believe that is possible. But parens around (-b) is the more standard solution. At Mon, 15 Sep 2008 02:24:14 +0200, Cetin Sert wrote:
Hi why do I get?
cetin@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 (-)
participants (4)
-
Brandon S. Allbery KF8NH
-
Cetin Sert
-
Daniel Fischer
-
Jeremy Shaw