I need to write a haskell program that retrieves a file from command line argument and read that file line by line. I was wondering how to approach this, do I have to get the command line argument as a string and parse that into openFile or something? I’m quite new to haskell so I’m pretty lost, any help would be appreciated!
Share
Yes, if one wants to specific a file as an argument then one will have to get the arguments and send that to openFile.
System.Environment.getArgsreturns the arguments as a list. So giventest_getArgs.hslikeThen,
So, if you want to read a single file:
(N.B. that code has no error recovery: what to do if there were no arguments and so
argswas empty (headwill fail)? What if the file doesn’t exist/isn’t readable?)