I'm still learning Haskell and I'm doing a few exercises, but I'm in a jam. So I have a function called "novel" which takes 2 Strings and an Int
(novel :: (String, String, Int) -> String) for its arguments. Novel's input/output must look like the following:
> novel ("Rowling", "Harry Potter", 1998)
"Harry Potter (Rowling, 1998)"
This is my code for my novel function which works as explained above:
novel :: (String, String, Int) -> String
novel (author, book, year) = book ++ " (" ++ author ++ ", " ++ (show year) ++ ")"
I am trying to write a new function called, "cite" (cite :: [(String, String, Int)] -> String). Cite's input/output should look like the following:
> cite [("author1", "book1", year1), ("author2", "book2", year2), ("author3", "book3", year3)]
"book1 (author1, year1)
book2 (author2, year2)
book3 (author3, year3)"
I am trying to use "novel," recursively, in order to get the desired output, but I am not sure how to go about this.
What I've tried:
cite :: [(String, String, Int)] -> String -- | Listed arguments
cite [] = "" -- | Base Case
cite x:xs = [(novel (author, book, year)), (novel (author, book, year)), (novel (author, book, year))]
This is honestly as far as I got. Obviously, it doesn't work, but I am not sure what to do from here.
mapfor ideas.String(i.e.[Char]) which uses "\n" in between each citation, or do you want to return[String]?mapcan perform any operation to the items of a list, not just arithmetic. AStringis the same as a list ofChars in Haskell. In fact, the typeStringis just a synonym for[Char].