How do you read the file specified as a function parameter when starting GHCI

I use ghci 6.10.4 on dos command line in XP as well as in emacs using haskell-mode-2.4

When starting programs running on stdin, is there a way to redirect the file to stdin? For example, if I have a main function that reads from stdin, I cannot:

*Main> main < words.txt

Is there another way?

I would also like to be able to type stdin into the ghci window, which seems to work, but what is the EOF key? I thought it was Ctrl-D, but it does not work.

+6
source share
2 answers

It will be easier if you rework your own mainto open the file itself.

import System.Environment
import System.IO

main :: IO ()
main = do
    args <- getArgs
    case args of
      [] -> doStuff stdin
      file:_ ->
        withFile file ReadMode doStuff

doStuff :: Handle -> IO ()
doStuff = 
* Main> System.Environment.withArgs ["main.txt"] main

EOF stdin GHCi. , stdin :

Prelude> getLine
*** Exception: <stdin>: hGetLine: illegal operation (handle is closed)
Prelude> getContents
*** Exception: <stdin>: hGetContents: illegal operation (handle is closed)
+6

: main GHCi . , , , .

+4

All Articles