Newest at the top
| 2026-06-16 16:11:29 +0000 | wickedja` | (~user@2605:8d80:8201:680e:dadb:dabd:d818:4b27) (Remote host closed the connection) |
| 2026-06-16 16:11:19 +0000 | <c_wraith> | I end up thinking of them as legacy names for 1) apply f to an accumulator with every element before returning or 2) immediately reduce to f with the first element and an unevaluated expression |
| 2026-06-16 16:11:05 +0000 | <int-e> | c_wraith: it does though if you know that you're supposed to view `f` as an infix operator and l and r refer to associativity of said operator |
| 2026-06-16 16:09:54 +0000 | karenw | (~karenw@user/karenw) karenw |
| 2026-06-16 16:06:24 +0000 | <c_wraith> | I wouldn't worry too much about the names "foldl" and "foldr". In particular, thinking of them as left or right really doesn't clarify anything. |
| 2026-06-16 16:04:18 +0000 | m_a_r_k | (~m_a_r_k@archlinux/support/mark) m_a_r_k |
| 2026-06-16 16:03:25 +0000 | m_a_r_k | (~m_a_r_k@archlinux/support/mark) (Remote host closed the connection) |
| 2026-06-16 16:02:49 +0000 | kuribas` | (~user@ip-188-118-57-242.reverse.destiny.be) (Remote host closed the connection) |
| 2026-06-16 15:53:26 +0000 | leppard | (~noOne@ipservice-092-208-182-236.092.208.pools.vodafone-ip.de) Inline |
| 2026-06-16 15:38:21 +0000 | wickedjargon | (~user@64.114.24.74) (Ping timeout: 242 seconds) |
| 2026-06-16 15:36:59 +0000 | wickedja` | (~user@2605:8d80:8201:680e:dadb:dabd:d818:4b27) |
| 2026-06-16 15:36:12 +0000 | <vms14> | ty for teaching me though, i appreciate it |
| 2026-06-16 15:34:49 +0000 | <vms14> | cool, i'll take your words :D |
| 2026-06-16 15:34:35 +0000 | <ski> | it's fine to ask questions, if things are unclear |
| 2026-06-16 15:34:17 +0000 | <vms14> | and i feel like you guys are wasting time teaching me basics i should learn by myself |
| 2026-06-16 15:33:56 +0000 | <vms14> | i do not know anything yet so i can't move properly |
| 2026-06-16 15:33:24 +0000 | <ski> | and, when it has seen all elements, it returns final accumulator |
| 2026-06-16 15:33:13 +0000 | <ski> | "fold left", say `foldl f z xs', starts from the front, with `z', combines each element of `xs', as it encounters then, into the `z' accumulator, using `f' to combine |
| 2026-06-16 15:32:51 +0000 | <lambdabot> | f a (f b (f c z)) |
| 2026-06-16 15:32:50 +0000 | <merijn> | > foldr f z [a,b,c] |
| 2026-06-16 15:32:50 +0000 | <vms14> | i want to play with sockets |
| 2026-06-16 15:32:48 +0000 | <lambdabot> | f (f (f z a) b) c |
| 2026-06-16 15:32:46 +0000 | <merijn> | > foldl f z [a,b,c] |
| 2026-06-16 15:32:41 +0000 | <merijn> | That's where simple-reflect is hekpful ;) |
| 2026-06-16 15:32:37 +0000 | <vms14> | well i have to keep reading, the real world haskell book seems it will be fun |
| 2026-06-16 15:32:01 +0000 | <vms14> | i guess the reverse |
| 2026-06-16 15:31:29 +0000 | <vms14> | foldr (+) 0 [1,2,3] 0 + 1 + 2 + 3 where foldl would be 1 + 2 + 3 + 0 |
| 2026-06-16 15:30:43 +0000 | <vms14> | and l or r is just where the 0 goes in that case? |
| 2026-06-16 15:30:31 +0000 | xal | (~xal@mx1.xal.systems) (Ping timeout: 276 seconds) |
| 2026-06-16 15:30:14 +0000 | xal_ | (~xal@mx1.xal.systems) xal |
| 2026-06-16 15:29:43 +0000 | <lambdabot> | 17 |
| 2026-06-16 15:29:41 +0000 | <ski> | > foldl (+) 0 [2,3,5,7] |
| 2026-06-16 15:29:36 +0000 | <lambdabot> | "((((0 + 2) + 3) + 5) + 7)" |
| 2026-06-16 15:29:34 +0000 | <ski> | > foldl (\s n -> "(" ++ s ++ " + " ++ show n ++ ")") "0" [2,3,5,7] -- or this ? |
| 2026-06-16 15:28:47 +0000 | <lambdabot> | 17 |
| 2026-06-16 15:28:45 +0000 | <ski> | > foldr (+) 0 [2,3,5,7] |
| 2026-06-16 15:28:34 +0000 | <lambdabot> | "(2 + (3 + (5 + (7 + 0))))" |
| 2026-06-16 15:28:33 +0000 | <ski> | > foldr (\n s -> "(" ++ show n ++ " + " ++ s ++ ")") "0" [2,3,5,7] -- can you see how this works ? |
| 2026-06-16 15:28:24 +0000 | <vms14> | foldr (+) 0 [1,2,3] |
| 2026-06-16 15:27:55 +0000 | phm | (~peter@fsf/member/phm) (Ping timeout: 264 seconds) |
| 2026-06-16 15:27:07 +0000 | <ski> | (or, actually works for other things than lists, as long as they are instances of `Foldable'. but it's basically a "list/sequence-like" type class, yes) |
| 2026-06-16 15:26:57 +0000 | <merijn> | vms14: Pretend that reads `foldl :: (b -> a -> b) -> b -> [a] -> b`. If you ponder that type, you should be able to figure out what it's doing |
| 2026-06-16 15:26:27 +0000 | <ski> | you combine all the elements of a list together into some result, one at a time |
| 2026-06-16 15:26:21 +0000 | <merijn> | ah, rats |
| 2026-06-16 15:26:19 +0000 | <lambdabot> | Foldable t => (b -> a -> b) -> b -> t a -> b |
| 2026-06-16 15:26:17 +0000 | <merijn> | :t Data.List.foldl |
| 2026-06-16 15:26:11 +0000 | <vms14> | oh |
| 2026-06-16 15:25:59 +0000 | <merijn> | if you know that |
| 2026-06-16 15:25:48 +0000 | <merijn> | vms14: foldl/foldr are with some squinting equivalent to, e.g. python's reduce |
| 2026-06-16 15:25:33 +0000 | <vms14> | just that lists can be seen as foldable and foldable seems to mean sequence |