IL CAPITANO
2011-02-20 17:55:45 UTC
hi all
i have this datatype
datatype tree = leaf of int | node of int*tree*tree; and a function
f:int->int
i write this function convert for apply f at all elemento of tree
fun convert(f,leaf(x))=leaf(f(x)) |
convert(f,node(x,t1,t2))= node(f(x),convert(f,t1),convert(f,t2));
how can write a convert for that Parametric Datatype
datatype ’a treeP = Empty | Node of ’a treeP * ’a * ’a treeP
i tryed this but i m not sure why i get problem whit no leaf
fun convert(f,Empty)=raise except |
convert(f,node(t1,x,t2))= node(convert(f,t1),f(x),convert(f,t2));
how can write a convert for that ’a treeP Parametric Datatype
i have this datatype
datatype tree = leaf of int | node of int*tree*tree; and a function
f:int->int
i write this function convert for apply f at all elemento of tree
fun convert(f,leaf(x))=leaf(f(x)) |
convert(f,node(x,t1,t2))= node(f(x),convert(f,t1),convert(f,t2));
how can write a convert for that Parametric Datatype
datatype ’a treeP = Empty | Node of ’a treeP * ’a * ’a treeP
i tryed this but i m not sure why i get problem whit no leaf
fun convert(f,Empty)=raise except |
convert(f,node(t1,x,t2))= node(convert(f,t1),f(x),convert(f,t2));
how can write a convert for that ’a treeP Parametric Datatype