Reputation: 1
I want to break down a 2-3-4 tree to small nodes.
These are the types I am using:
type ele = int
type color = Red|Black
type ab = Vide | Node of ( ele * color * ab * ab *ab)
type ab234 = Vide
|Node_1 of (ele * ab234* ab234)
|Node_2 of(ele * ele * ab234 *ab234 *ab234) ``
|Node_3 of(ele * ele * ele *ab234 * ab234* ab234 *ab234)
I based my mapping on this:
I need help doing my transformation. I tried with this function but it doesn't seem to work, it does break down the root but it doesn't continue to the branches:
let rec eclat = function
| Vide -> Vide
| Node_3(r,x,y,ag,mg,md,ad) -> eclat ( Node_1(x,(Node_1(r,ag,mg)),Node_1(y,md,ad)))
| Node_2(r,x,ag,ml,ad) -> eclat(Node_1(r,(Node_1(x,ag,ml)),ad))
| _ -> failwith("zebi") ;;
Upvotes: 0
Views: 176
Reputation: 66823
If I enter your eclat
function as you have it now, I get this:
Hint: If this is a recursive definition, you should add the 'rec' keyword on line 1
So that's one problem.
I also note that you changed ab
to ab234
, but you didn't change the internal appearances inside the type. So the contents of the ab234
type are all defined to be of type ab
. This doesn't seem correct.
Upvotes: 1