I have a function called mergeP:如何在sml中重複調用另一個函數?
fun mergeP(nil) = nil
| mergeP(x::[]) = x::[]
| mergeP(x::y::zs) = (x @ y)::mergeP(zs);
If
mergeP
is called like:mergeP([[1],[2],[3],[4]])
it will return[[1,2],[3,4]]
. I want to create a function calledmergeS
that is recursive that repeatedly callsmergeP
till the sublist equals just one list. So ifmergeS
were called like:mergeS([[1],[2],[3],[4]])
it would repeatedly callmergeP
till it equals:[1,2,3,4]
. Here is my try:
- fun mergeS(nil) = nil
= |mergeS(xs) = mergeS(mergeP(xs));
But this gives me the error:
stdIn:6.1-6.26 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
val it = [] : ?.X1 list
我不認爲你可以定義一個函數來「移除」SML類型系統中任意數量的列表嵌套層次。 – molbdnilo