我正在尝试以下代码:
readALine :: FilePath -> IO ()
readALine fname = do
putStr . show $ "Filename: " ++ fname ++ "; "
hand <- openFile fname ReadMode
if getFileSize hand > 0 then do
fline <- hGetLine hand
hClose hand
print $ "First line: " <> fline
else return ()
但是它给出了以下错误:
$ runghc firstline2.hs
firstline2.hs:20:18: error:
• Couldn't match type ‘GHC.IO.Handle.Types.Handle’ with ‘[Char]’
Expected type: FilePath
Actual type: GHC.IO.Handle.Types.Handle
• In the first argument of ‘getFileSize’, namely ‘hand’
In the first argument of ‘(>)’, namely ‘getFileSize hand’
In the expression: getFileSize hand > 0
问题出在哪里,如何解决?感谢您的帮助。