我正在尝试在SML上编写一个函数,该函数将反转第一个列表,然后将其与第二个列表连接起来(类似于:list1 = [5,3,1]和list2 = [6 7 8],那么inv(list1,list2) = [1,3,5,6,7,8])。以下是代码:
fun inv (nil,nil) = []
|inv (ha::ta,hb::tb) =
if ha = [] then ta::(hb::tb)
else ha::inv(ta,hb::tb);
它返回以下内容:
错误:if分支的类型不一致[circularity] 然后分支:''Z列表列表列表 否则分支:''Z列表列表 在表达式中:
如果ha = nil,则ta :: hb :: tb,否则ha :: inv (ta,:: )。
请问有谁能帮帮我吗?
fun inv (xs, ys) = rev xs @ ys
- sshine