I am trying to create a function profit_report :: [String] -> [Transaction] -> String
that takes a list of stocks and a transaction log, and returns the human-readable string containing the profit and loss report.
Specifically, for each stock in the input list, the report should include the line STOCK: PROFIT
where STOCK
is the name of the stock, and PROFIT
is the amount of profit made. The stocks should appear in the order in which they are listed in the input.
For example: the function can be tested using putStr
like so:
ghci> putStr (profit_report ["VTI", "ONEQ", "IWRD"] test_log)
VTI: 14450
ONEQ: -800
IWRD: -1900
Here is some background information.
The transaction log looks like this:
test_log :: [Transaction]
test_log = [('B', 100, 1104, "VTI", 1),
('B', 200, 36, "ONEQ", 3),
('B', 50, 1223, "VTI", 5),
('S', 150, 1240, "VTI", 9),
('B', 100, 229, "IWRD", 10),
('S', 200, 32, "ONEQ", 11),
('S', 100, 210, "IWRD", 12)
]
CodePudding user response:
You have the type declaration
profit_report :: [String] -> [Transaction] -> String
meaning your function takes 2 arguments.
But here you only match one:
profit_report [] = []
-- ^^
profit_report (x:xs) = x : get_trades x (x:xs) : profit(x xs)
-- ^^^^^^
You're missing a 2nd argument in both cases
CodePudding user response:
I have this assignment also, I think you'll find that you are allowed to use importations in this assignment, it says so in the FAQ section at the bottom of the assignment pdf.