Ask Your Question
2

How can Haskell utilize a file argument from the command line using ".."?

asked 2021-06-21 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-02-01 01:00:00 +0000

qstack gravatar image

In Haskell, the file argument from the command line can be utilized using the System.Environment module. The ".." argument specifies the parent directory.

Here is an example code snippet:

import System.Environment

main = do
    args <- getArgs
    let fileName = "../" ++ head args -- add ".." prefix to file name
    fileContents <- readFile fileName
    putStrLn fileContents

In this example, we use the getArgs function to retrieve the command line arguments. We use the head function to get the first argument, which is assumed to be the file name. We then add the ".." prefix to the file name using the ++ operator. Finally, we use the readFile function to read the contents of the file and print it to the console using the putStrLn function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-21 11:00:00 +0000

Seen: 11 times

Last updated: Feb 01 '22