Problem with do construct in haskell

Posted by Anonymous Coward on Stack Overflow See other posts from Stack Overflow or by Anonymous Coward
Published on 2010-12-22T20:26:06Z Indexed on 2010/12/22 20:54 UTC
Read the original article Hit count: 244

Filed under:
|
|

Hello everyone

I'm trying to learn Haskell and want to write a small program which prints the content of a file to the screen. When I load it into GHCi I get the following error:

The last statement in a 'do' construct must be an expression

I know this question has be asked already here: Haskell — “The last statement in a 'do' construct must be an expression”.

Even though my code is very similar I still can't figure out the problem. If anyone could point out the problem to me I'd be very thankful.

module Main (main) where

import System.IO
import System(getArgs)

main :: IO()
main = do
    args <- getArgs
    inh <- openFile $ ReadMode head args
    printFile inh
    hClose inh

printFile :: Handle -> IO ()
printFile handle = do
    end <- hIsEOF handle
        if end
            then return ()
            else do line <- hGetLine handle
                putStrLn line
                printFile handle

© Stack Overflow or respective owner

Related posts about haskell

Related posts about do