hey guys, have no idea how to traverse multiway trees and build a list of strings
pastebin
Very likely that you need to use a syntax extension which will generate a traversal function for you. https://github.com/ocaml-ppx/ppx_deriving has an iter plugin for it. I would start from there
You may also be interested in the visitors ppx.
I am not sure if recommanding code generation tools is a good answer here. Sure, writing the traversal code is boring, but it is also quite straightforward. In my opinion it is far better to first understand how to write such traversal function before moving to generating tools.
@locaml, what did you try? If you are completely lost, a first good step since html_tree is a variant is to pattern match the html_tree argument in display_html.
Exactly my thoughts.
Thanks for your advice! check it pls pastebin
This is a good first next. The next two steps are:
- First, determine the result of
display_htmlfor the base caseWord sandEmpty. If you wanted to map these two case to a list of string, what will you do ? (hint: you should build a list here) - Second, the function
display_html_listshould not look at the content of the element of the list: this is the job ofdisplay_html. The job ofdisplay_html_listis to patch together the list created bydisplay_html. You should remove theloadfunction and start by pattern matching the list (without extending the individual elements).