Haskell: What does the compiler mean by this?
Hello,
once the code:
module Task29 where import System.IO main :: IO () main = do hSetBuffering stdout NoBuffering -- needed depending on your operating system and settings putStrLn "Bitte gebe die erste Zahl ein:" x1 <- readLn putStrLn "Zweite" x2 <- readLn let sum = x1 + x2 print ("Die Summe ist:" ++ show(sum)) result <- while (x1,1) (\x -> x/=0) (\(x,count) -> do putStrLn "Bitte gebe die erste Zahl an" x1 <- readLn putStrLn "Zweite" x2 <- readLn let sum = x1 + x2 print ("Die Summe ist:" ++ show(sum)) return (x1,(count+1))) print ("Anzahl additionen:" ++ show(snd(result))) while :: a -> (a -> Bool) -> (a -> IO a) -> IO a while ap body = loop a where loop x = if px then do x'<- body x loop x' else return x
And once the complaint:
The same applies to let sum = x1 + x2, to show and to the 1 in the tuple (x1,1), and to /=0.
I don't understand what he's trying to tell me and how I can solve this.
Thanks in advance:))
x1 and x2 are supposed to record floating point numbers, which are then added in the further course of the program execution.
The problem is that Haskell does not determine the data type of X1, x1 and therefore cannot decide which definition of readLn is to be used.
In a very shortened example, I show two possible ways:
first way: auxiliary function for reading a float value:
Second way: Use of a cast:
Something in the way could help in your program.