암튼...
그때는 꼭 ヨコハマ買い出し紀行(카페알파)도 구입할 수 있게 되기를...
최근의 수확은 다음의 것.
File Reading in Haskell
module Main
where
import IO
main = do hSetBuffering stdin LineBuffering
doLoop
doLoop = do
putStrLn "Enter a command rFN WFN or q to quit: "
command <- getLine
case command of
'q':_ -> return ()
'r':filename -> do putStrLn ("Reading " ++ filename)
doRead filename
doLoop
'w':filename -> do putStrLn ("Writing " ++ filename)
doWrite filename
doLoop
_ -> doLoop
doRead filename =
bracket (openFile filename ReadMode) hClose
(\h -> do contents <- hGetContents h
--putStrLn "The first 100 chars: "
putStrLn (head $ lines contents)) -- hgetContents는 IO String을 반환. ->를 통해서 Var에 String으로 저장.
--putStrLn (take 100 contents))
doWrite filename = do
putStrLn "Enter text to go into the file: "
contents <- getLine
bracket (openFile filename WriteMode) hClose
(\h -> hPutStrLn h contents)

No comments:
Post a Comment