I am trying to write the function trade_report :: String -> [Transaction] -> String
which will take an element in a list and return the values associated with the element.
For context in what the Type transaction is:
type Transaction = (Char, Int, Int, String, Int)
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:
get_trades
returns a list of Transaction
values. transaction_to_string
only takes a single Transaction
value. You need to use map
.
> :t transaction_to_string
transaction_to_string :: Transaction -> String
> :t map transaction_to_string
map transaction_to_string :: [Transaction] -> [String]
Once you have your list of String
values, you can join them together with \n
characters using Data.List.intercalate
.
> import Data.List
> intercalate "\n" ["foo", "bar"]
"foo\nbar"