You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Recursion is when a function that calls itself until it reaches its solution.
5
+
-- Anything that can be accomplished via iteration can be done using recursion.
6
+
-- Haskell has only recursion, no looping.
7
+
last':: [a] ->a
8
+
last' (x:[]) = x
9
+
last' (x:xs) = last' xs
10
+
11
+
-- Failure in recursion
12
+
-- Infinite recursion - If the recursive function does not have a proper termination condition or if the termination condition is not reached due to some logical error, the recursion can continue indefinitely, resulting in an infinite loop. This can cause the program to run out of memory or hang indefinitely.
13
+
-- Stack overflow - Haskell uses a call stack to keep track of function calls. If the recursion goes too deep without proper termination, it can exhaust the call stack space, leading to a stack overflow error.
14
+
-- Incorrect base case - If the base case(s) of the recursive function is not defined correctly, it can lead to unexpected behavior or incorrect results.
15
+
-- Incorrect recursive call - If the recursive call within the function is not defined correctly or if the arguments passed to the recursive call are incorrect, it can lead to incorrect results or unexpected behavior.
16
+
17
+
-- Debug.Trace can be used to show the steps that the recursion takes. (Imported above).
0 commit comments