コード:
main = do
putStrLn "4917 Microprocessor\nEnter the Machine Code to be run: "
inp <- getContents
putStrLn "The output of the Program is:"
fState <- ((runStateT _4917) . construct . parse) inp
args <- getArgs
if elem "-v" args then putStrLn ("\nFinal state was: " ++ (show . snd) fState) else return ()
putStrLn "\n================================ RESTART ================================"
main
where parse xs = array (0,15) $
zip [0..15] $
take 16 $
map ((makeArbInt 4) . read) (words (filter ((/=)'.') xs)) ++ repeat (makeArbInt 4 0)
construct xs = Program xs z z z z 0 False
z = (makeArbInt 4 0)
もっとありますが、これは関連する部分です。基本的に、3 行目は複数回評価する必要がありますが、getContents は stdin ハンドルを閉じています。
4917: <stdin>: hGetContents: illegal operation (handle is closed)
ハンドルを再び開く方法はありますか?または、 getContents がそれを行うのを防ぐ方法はありますか? (間違ったシグナルを送信しているのかもしれません。Linux で Ctrl-D EOF を送信しています。代わりに EOT などを使用する必要がありますか?)
編集: 目的の動作を得ることができましたが、Windows には移植されません。
mystdin <- openFile "/dev/tty" ReadMode
inp <- hGetContents mystdin
新しい質問: stdin へのハンドルをポータブルに開く一般的な方法はありますか?