我有这些功能:
first_threes :: [Int] -- first three numbers repeated
first_threes = 1:2:3:first_threes -- th.1
take :: Int -> [a] -> [a] -- take
take 0 _ = [] -- t.1
take n (x:xs) = x : (take (n - 1) xs) -- t.2
sum :: [Int] -> Int -- summation of an Int list
sum [] = 0 -- s.1
sum (x:xs) = x + (sum xs) -- s.2
我必须评估" bonnet"每个步骤中的编译器。到目前为止,我有这个:
1. my_sum (my_take 5 first_threes) =
2. my_sum (my_take 5 (1:2:3:first_threes)) =
3. my_sum (1:(my_take 4 (2:3:first_threes))) =
4. 1 + my_sum (my_take 4 (2:3:first_threes))=
5. 1 + my_sum (2:(my_take 3 (3:first_threes)))=
6. 1 + 2 + my_sum (my_take 3(3:first_threes))=
7. 1 + 2 + my_sum (3: (my_take 2([]:first_threes)))=
8. 1 + 2 + 3 + my_sum( my_take 1([]:first_threes))=
9. 1 + 2 + 3 + my_sum( my_take []([]:first_threes))=
这是对的吗?我需要知道,因为我可以评估每一步中发生了什么,但是在我知道我已经完成了编译器正确执行的每一步之前,我不能这样做。任何打击都会非常感激。谢谢x