I'll get right to it (I removed a bunch of extraneous code, in case this looks a little funny -- trying to make this a MCVE):
import System.IO
import Control.Monad
import Data.IORef
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
input_line <- getLine
let input = words input_line
let x0 = read (input!!0) :: Int
x <- newIORef x0
loop
loop :: IO ()
loop = do
input_line <- getLine
let the_dir = input_line :: String
putStrLn x
loop
Just to test it I tried outputting x and it's saying it's out of scope. Why? How do I fix it so it is in scope? I need to access the variables but I also need to have them initialized before I enter the loop for the first time.
loopaccept an input parameter and passxto it?IORefand such?