Я хочу писать функции и помещать результат в строку.
Мне нужна функция:
read' :: FilePath -> String
Я использую:
:t readFile
readFile :: FilePath -> IO String
Я делаю:
read' :: IO ()
read' = do
str <- readFile "/home/shk/workspace/src/test.txt"
putStrLn str
Я хочу спросить, str это строка или нет?
Мы знаем, что:
:t putStrLn
putStrLn :: String -> IO ()
Тогда почему я не могу:
read' :: String
read' = do
str <- readFile "/home/shk/workspace/lxmpp/src/test.txt"
str
Я получаю сообщение об ошибке:
Couldn't match expected type `[t0]' with actual type `IO String'
In the return type of a call of `readFile'
In a stmt of a 'do' expression:
str <- readFile "/home/shk/workspace/lxmpp/src/test.txt"
In the expression:
do { str <- readFile "/home/shk/workspace/src/test.txt";
str }
Спасибо.