[haskell/en] Minor changes that were bothering me (#5207)

This commit is contained in:
Evan Hock 2024-12-09 02:47:38 -08:00 committed by GitHub
parent c8af038bda
commit d9225142d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -66,6 +66,7 @@ True || False -- True
['H', 'e', 'l', 'l', 'o'] -- "Hello" ['H', 'e', 'l', 'l', 'o'] -- "Hello"
-- Lists can be indexed with the `!!` operator followed by an index -- 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' "This is a string" !! 0 -- 'T'
@ -273,7 +274,7 @@ case args of
map (*2) [1..5] -- [2, 4, 6, 8, 10] map (*2) [1..5] -- [2, 4, 6, 8, 10]
-- you can make a for function using map -- you can make a for function using map
for array func = map func array for list func = map func list
-- and then use it -- and then use it
for [0..5] $ \i -> show i for [0..5] $ \i -> show i
@ -281,6 +282,9 @@ for [0..5] $ \i -> show i
-- we could've written that like this too: -- we could've written that like this too:
for [0..5] show 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 -- You can use foldl or foldr to reduce a list
-- foldl <fn> <initial value> <list> -- foldl <fn> <initial value> <list>
foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43 foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43