160 likes | 283 Vues
This text delves into the execution of Haskell programs, specifically the power function implemented using recursion. We explore how functional programs execute mathematical operations step by step, illustrating the recursive nature of functions such as power. By examining the evaluation of the power function, we can see how base cases and recursive calls unfold in the computational model, unveiling the principles behind functional programming in Haskell.
E N D
Formal Models of Computation Running Haskell Programs – power
How functional programs work… We have seen simple programs such as Let’s now see how they are executed Given the program above, we get the following: But how? power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 8 formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) 3matches(n+1), assigning 2 to n power 23 formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (power 2 2) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (power 2 2) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (power 2 2) 2matches(n+1), assigning 1 to n formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (power 2 1)) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (power 2 1)) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (power 2 1)) 1matches(n+1), assigning 0 to n formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (2 * (power 2 0))) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (2 * (power 2 0))) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (2 * (power 2 0))) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 2 * (2 * (2 * (1))) formal models of computation
How functional programs work… Execution: power x 0 = 1 power x (n+1) = x * (power x n) power 2 3 8 formal models of computation