So, I'm trying to make a program that reads from a descriptor and writes to stdOut, for example:
import IO
import System
cat w = do
fromHandle <- getAndOpenFile w ReadMode
contents <- hGetContents fromHandle
putStr contents
putStr "Done."
getAndOpenFile :: String -> IOMode -> IO Handle
getAndOpenFile name mode =
do
catch (openFile name mode)
(\_ -> do
putStrLn ("Cannot open "++ name ++"\n")
return())
I am new to Hs and it seems like it should be a lot easier than I do it for myself. Any suggestions that will help me move on?
use will be. / cat "foo.txt" and will display the text in the foo.txt file in stdOut.
source
share