From 0935026210bbedfe1d261622f4dd8976b03de54e Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 3 Jul 2025 21:27:41 +0200 Subject: improve takeNth's comment from first exercise --- lec03/Golf.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lec03') diff --git a/lec03/Golf.hs b/lec03/Golf.hs index e4fa9a3..de3af42 100644 --- a/lec03/Golf.hs +++ b/lec03/Golf.hs @@ -4,9 +4,10 @@ module Golf where -- Explanation: -- takeNth takes the nth value of a list without crashing. First, it drops all --- the first `n - 1` elements from the list. Then, it takes the desired element. --- This function is total and can be thought of as the total version of the --- partial function `!!`. +-- the first `n - 1` elements from the list. Then, it takes the desired element +-- and returns it as a list. If the element can't be found, it returns an empty +-- list. This function is total and can be thought of as the total version of +-- the partial function `!!`. takeNth :: [a] -> Int -> [a] takeNth l n = take 1 $ drop (n-1) l -- cgit v1.2.3