0

I am trying to come up with a datatype for a general tree. I tried writing

datatype 'a TREE = null | Node of 'a * 'a TREE list;

but it didn't work out. My idea is to create a list of child nodes for a parent node and then each of the nodes in this list will be the parent node for another lists of nodes and so on. How can this be achieved?

Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
  • What exactly "didn't work out"? – Ionuț G. Stan Feb 29 '16 at 12:37
  • The `null` seems unnecessary - either a node has children and its child list is non-empty, or it hasn't and it's empty. Do you have a use case for it? (Making sure that no `null` children creep into the child list sounds messy.) – molbdnilo Mar 02 '16 at 10:54

0 Answers0