the Nested List can exist in Scheme, but is it legal to use nested-list in SML? or we can only use simple list in SML?
and if legal,
1) how to check wether the two input list have the same list structure. algorithm the atoms in the list are not equal.
2) Whatever the deep of the input list, how to delete all the atoms in the nested-list that equals to the input value: a. should use the original list and not create a new list.
There's no problem in having nested lists in Standard ML. For an example:
is an example of an
int list list
, i.e., a list of lists of integers.As for your additional questions.
1
If by same structure you mean whether the sublists contain the same number of elements, i.e, you want
Then you can simply make a recursive function on the lists, that compares the length of each sublist in turn.
Note, if the lists are nested more than once, you'll need a function for each level. (i.e., one for
'a list list
s, one for'a list list list
s, etc.2
You cannot make a function that "however deep the input list" does something to the elements in the list. The type system will not let you do this. This is similar to how you cannot make the following list:
This is due to a list only being allowed to contain one type of elements, so if you have an
'a list list
, each element in the list must be an'a list
. You cannot have'a
s directly.You'll have to settle on how nested the lists are, and make a function specific to that depth.