I'm trying to create a program in Haskell that takes in user inputs, adds each input line up, and spits out the final sum once the user inputs a negative number (the total sum not including the negative number, to be specific). I attempt
sumF1 :: IO () sumF1 = do totSum <- sumF2 0 print totSum sumF2 :: Int -> IO Int sumF2 prev = do n<-getInt if n<0 then return prev else sumF2 (prev+n) However, when I try this, I just get a function that prints on every single line and always repeats the input as opposed to summing it up. How do I fix it so that it only prints a sum at the end and that it adds properly.
getInt :: IO Int; getInt = fmap read getLineor equivalent). Either you're not showing us all your code or you're trying to do something else.