jaevoice.blogg.se

Haskell functional programming as a liberal arts
Haskell functional programming as a liberal arts




I'd argue that expanding it a bit might be better for understanding for the next reader.What is the end goal here? Does she actually want a job doing computer-y things in the long term or is she just looking for something to add to her resumé to differentiate herself from the crowd? fmap is a bit too complicated for me to follow. However, I actually think it makes it worse in terms of readability. Since you're already using fmap liberally I also thought about the following: filterStocks = V.filter $ fmap (= "Common Stock") instrumentType I'd probably inline the local function in filterStocks, because I don't think it adds much clarity over an anonymous function: filterStocks = V.filter (\instrument -> instrumentType instrument = "Common Stock") Maybe "Read raw CSV data from a file", similar to readStocks. Some of the comments could be better, like parseCsv saying "Function to read the CSV" - well, yes, we can see that from the name already. IMO Csv looks odd, but the package is already using the name, I guess that's fine. I'm sure that could be done nicer, this one would also need ScopedTypeVariables enabled. From the signature I'd actually expect this to be handled via the Either: parseCsv filePath = do parseCsv for example checks for the existence of the file - that's a big hint that the function doesn't work in all circumstances as expected, like if the file exists, but isn't readable (try chmod a-r test-resources/empty-file.csv and see how it results in an uncaught exception *** Exception: test-resources/empty-file.csv: openBinaryFile: permission denied (Permission denied)). The first thing I've noticed, is the error handling for opening files. Looks great overall, especially how you've included instructions on running it, even with sample data, makes this a great submission. IsStock stock = instrumentType stock = "Common Stock"įilterStocks :: V.Vector Stock -> V.Vector Stock Check if the given element is a Common Stock ParseCSV :: FilePath -> IO (Either ErrorMsg CsvData) type synonyms to handle the CSV contents I read this section of Stephen Diehl's guide before writing the code: What I wish I knew when learning Haskell The code is a Stack project, you can find the project and instructions on how to run it: here Filter the stocks that are "Common Stock" -> Īny feedback on how to write better Haskell code is appreciated!.Parse the headers and rows from the CSV to a tuple -> (headers, ).Read rows from a CSV -> return lazy byte string.I'm not sure if this is the appropriate way to do it.






Haskell functional programming as a liberal arts