哈斯克尔中元组列表上的递归



有没有递归的方式来做下面这样的事情?

    updateOs2 :: [(Rotor, Int)] -> [(Rotor, Int)]
    updateOs2 [(a,x),(b,y),(c,z)]
        | x == 25 && y == 25 && z == 25 = [(a,0),(b,0),(c,0)]
        | x == 25 && y == 25            = [(a,0),(b,0),(c,z+1)]
        | x == 25                       = [(a,0),(b,y+1),(c,z)]
        | otherwise                     = [(a,x+1),(b,y),(c,z)]

我尝试过递归,但很困惑。因为一旦传递z最后一个元素,列表就会变为空,无法再返回到x

我认为这应该有效

updateOs2 [] = []
updateOs2 ((a,x):xs)
    | x == 25 = (a,0): (updateOs2 xs)
    | otherwise =  (a,x+1):xs

最新更新