ファイルを読む @haskell
import System.IO main = do fileName <- getLine let content = readFile fileName putStrLn content
[1 of 1] Compiling Main ( main.hs, main.o ) main.hs:6:14: error: • Couldn't match type ‘IO String’ with ‘[Char]’ Expected type: String Actual type: IO String • In the first argument of ‘putStrLn’, namely ‘content’ In a stmt of a 'do' block: putStrLn content In the expression: do fileName <- getLine let content = readFile fileName putStrLn content | 6 | putStrLn content | ^^^^^^^
import System.IO main = do fileName <- getLine content <- readFile fileName putStrLn content
ダメだった原因
readFileの戻り値の型がIO stringだったので
let = ではなく <-でString だけ取るようにしないといけなった。
※memo
stmt = statement