Recursion can bite you big time if you're not careful

I started taking a Programming Languages MOOC, which aims to teach similarities between all languages through examples in ML. While illustrating the benefits of ML’s LET command, the instructor presented this intentionally poorly written algorithm for finding the maximum value in a list: // Let Expressions to Avoid Repeated Computation fun bad_max (xs : int list) = if null x then 0 else if null (tl xs) then hd xs else if hd xs > bad_max(tl xs) then hd xs else bad_max(tl xs) Around 25-30 numbers, it gets reallllly slow. I figured I’d translate it to »