From d9225142d0b48195c6303e8e59a067c03f69a4cd Mon Sep 17 00:00:00 2001 From: Evan Hock <91491099+Evan-Hock@users.noreply.github.com> Date: Mon, 9 Dec 2024 02:47:38 -0800 Subject: [PATCH] [haskell/en] Minor changes that were bothering me (#5207) --- haskell.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/haskell.md b/haskell.md index 1e1eb65a..29dcfc3d 100644 --- a/haskell.md +++ b/haskell.md @@ -66,6 +66,7 @@ True || False -- True ['H', 'e', 'l', 'l', 'o'] -- "Hello" -- Lists can be indexed with the `!!` operator followed by an index +-- but this is an O(n) operation because lists are linked lists "This is a string" !! 0 -- 'T' @@ -273,7 +274,7 @@ case args of map (*2) [1..5] -- [2, 4, 6, 8, 10] -- you can make a for function using map -for array func = map func array +for list func = map func list -- and then use it for [0..5] $ \i -> show i @@ -281,6 +282,9 @@ for [0..5] $ \i -> show i -- we could've written that like this too: for [0..5] show +-- filter keeps only the elements in a list that satisfy a condition +filter even [1..10] -- [2, 4, 8, 10] + -- You can use foldl or foldr to reduce a list -- foldl foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43