datatype 'a F = A of 'a F list | B of 'a | C
Write a function called toList
to
return a list of values of type 'a
from a
data structure of type 'a F
, keeping the
left to right traversal order of the elements.
(* toList : 'a F -> 'a list toList f = list of elements of type 'a preserving the order of left to right traversal of the f tree (of type 'a F) *)You are allowed to define auxiliary functions.
toList C = []; toList (B 3) = [3]; toList (A[]) = []; toList (A[A[],A[],C,A[],C]) = []; toList (A[B 5.4,C,A[],B 13.6,B 7.7]) = [5.4, 13.6, 7.7]; toList (A[B 5,A[B 5,B 765,B 875],A[],A[B 7,A[],B 76,A[]]]) = [5, 5, 765, 875, 7, 76]; toList (A[B#"c",C,A[],B#"i",B#"k"]) = [#"c", #"i", #"k"];