0
내가 추적하는 데 문제
추적 :는 (정확하다)이 코드를 OCaml의 재귀 기능
let rec prepend (l: int list list) (x: int) : int list list =
begin match l with
| [] -> []
| hd :: tl -> (x :: hd) :: (prepend tl x)
end
prepend [[]; [2]; [2;3]] 1 = [[1]; [1;2]; [1;2;3]]
내 추적이 잘못된 것입니다,하지만 난 잘못 모르겠어요 :
prepend ([]::2::[]::2::3::[]::[]) 1 =
1::[]::prepend (2::[]::2::3::[]::[]) 1 =
1::[]::1::2::prepend([]::2::3::[]::[]) 1 =
1::[]::1::2::1::[]::prepend(2::3::[]::[]) 1 -->
This is incorrect because then it comes out as [1] ; [1;2;1]
when it should be [1]; [1;2] ; [1;2;3]
은, 정말 감사합니다! – user