I am trying to implement menu function that returns all titles from custom data type Page
data Page = Text String
| Title String [Page] deriving(Show)
menu :: Page -> [String]
menu (Text a) = []
menu (Title name content ) = [name]
But I want also this function will work also for some "hierarchy" of pages, for example, like in index :
index = Title "Home" [
Title "Welcome!"[
Text "Hello World!",
Title "Lorem"[Text "ipsum"]],
Title "dolor"[
Title "no title" [Text "Haskell"],
Title "Look!" [Text "test"]],
Title "Finish" [Text "It will be look great"]]
I done some functions for this, but I have no idea how to start recursion for "hierarchy" Page
menu :: Page -> [String]
menu (Text a) = []
menu (Title name content ) = [name]
The output is
*Main> menu index
["Home"]
But can I do list of all Title in index ?
Thanks a lot in advance for answer!
menuover that, and you'll get a list of lists. Concatenate those lists, then prependnameto the result.