From 5979e3c52ee18ed881878174fdf16b6e3e606200 Mon Sep 17 00:00:00 2001 From: joMarsch <106771284+joMarsch@users.noreply.github.com> Date: Wed, 18 Sep 2024 08:21:28 +0200 Subject: [PATCH] Update about.md (#1279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The accumulator needs to be returned by the functions otherwise the won’t work correctly. --- concepts/recursion/about.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/concepts/recursion/about.md b/concepts/recursion/about.md index 3f4ed177e..991e30127 100644 --- a/concepts/recursion/about.md +++ b/concepts/recursion/about.md @@ -39,7 +39,7 @@ Here is a tail-recursive version of the list length function: ```fsharp let rec lengthRecursive acc list = match list with - | [] -> 0 + | [] -> acc | x::xs -> lengthRecursive (acc + 1) xs let length list = lengthRecursive 0 list @@ -51,7 +51,7 @@ It is quite common to define the recursive helper as a nested function, which hi let length list = let rec lengthRecursive acc remainder = match remainder with - | [] -> 0 + | [] -> acc | x::xs -> lengthRecursive (acc + 1) xs lengthRecursive 0 list