Logs: liberachat/#haskell
| 2021-05-29 21:45:28 | → | favonia joins (~favonia@user/favonia) |
| 2021-05-29 21:45:47 | × | waleee quits (~waleee@2001:9b0:216:8200:d457:9189:7843:1dbd) (Ping timeout: 244 seconds) |
| 2021-05-29 21:45:51 | <pavonia> | Is there no monadic version of foldl for ByteStrings? |
| 2021-05-29 21:46:03 | <hololeap> | ok, yeah that's what I was curious about. I've used sway a bit and it was pretty cool, but I keep going back to plasma |
| 2021-05-29 21:46:26 | × | abhixec quits (~abhixec@c-67-169-139-16.hsd1.ca.comcast.net) (Ping timeout: 265 seconds) |
| 2021-05-29 21:47:38 | × | fendor quits (~fendor@178.165.129.15.wireless.dyn.drei.com) (Remote host closed the connection) |
| 2021-05-29 21:47:49 | → | waleee joins (~waleee@2001:9b0:216:8200:d457:9189:7843:1dbd) |
| 2021-05-29 21:47:54 | <dminuoso> | pavonia: You can handroll that trivially |
| 2021-05-29 21:48:07 | <dminuoso> | foldlM f z0 xs = foldr c return xs z0 where c x k z = f z x >>= k |
| 2021-05-29 21:48:14 | <hololeap> | pavonia: there's also something in mono-traversable |
| 2021-05-29 21:48:17 | <dminuoso> | Is the definition of foldlM from base, you can copy that straight |
| 2021-05-29 21:48:54 | <hololeap> | https://hackage.haskell.org/package/mono-traversable-1.0.15.1/docs/Data-MonoTraversable.html#v:ofoldlM |
| 2021-05-29 21:49:27 | <dminuoso> | I found that mono-traversable is overkill for "that single function" usually :p |
| 2021-05-29 21:49:37 | <hololeap> | fair enough |
| 2021-05-29 21:49:59 | <pavonia> | dminuoso: Is that traversing from left to right? |
| 2021-05-29 21:50:13 | → | merijn joins (~merijn@83-160-49-249.ip.xs4all.nl) |
| 2021-05-29 21:50:18 | × | involans quits (~alex@cpc92718-cmbg20-2-0-cust157.5-4.cable.virginm.net) (Ping timeout: 265 seconds) |
| 2021-05-29 21:50:33 | <dminuoso> | pavonia: right-associative in effects, left-associative in its output |
| 2021-05-29 21:50:41 | <dminuoso> | See https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Foldable.html#v:foldlM |
| 2021-05-29 21:51:12 | → | abhixec joins (~abhixec@c-67-169-139-16.hsd1.ca.comcast.net) |
| 2021-05-29 21:51:20 | <pavonia> | After more than 10 years in Haskell, those folds are still confusing me :S |
| 2021-05-29 21:51:57 | <dminuoso> | pavonia: the main thing to understand is that foldr/foldl dont fold in different directions |
| 2021-05-29 21:52:19 | → | ddellacosta joins (~ddellacos@89.46.62.25) |
| 2021-05-29 21:52:37 | <pavonia> | Yeah, it depends on the function |
| 2021-05-29 21:52:47 | × | favonia quits (~favonia@user/favonia) (Ping timeout: 245 seconds) |
| 2021-05-29 21:53:16 | <dminuoso> | nope |
| 2021-05-29 21:53:29 | <pavonia> | ? |
| 2021-05-29 21:53:40 | → | pfurla joins (~pfurla@ool-182ed2e2.dyn.optonline.net) |
| 2021-05-29 21:54:20 | → | favonia joins (~favonia@user/favonia) |
| 2021-05-29 21:54:51 | <davean> | pavonia: its the side the parens are placed on |
| 2021-05-29 21:55:01 | <dminuoso> | try to imagine a fold as turning your structure into a list [1 2 3 4], and then putting a function between those elements [1 `f` 2 `f` 3 `4`] |
| 2021-05-29 21:55:05 | <davean> | pavonia: the fold its self always progresses from the start of the datastrcuture to the end |
| 2021-05-29 21:55:09 | <dminuoso> | the difference between foldr and foldr is how this associates |
| 2021-05-29 21:55:11 | <dminuoso> | that is whether it becomes |
| 2021-05-29 21:55:26 | <dminuoso> | ((1 `f` 2) `f` 3) `f` 4 |
| 2021-05-29 21:55:27 | <dminuoso> | or |
| 2021-05-29 21:55:41 | <dminuoso> | 1 `f` (2 `f` (3 `f` 4)) |
| 2021-05-29 21:56:04 | <dminuoso> | I indentionally ignored the final element for pedagogic purposes. |
| 2021-05-29 21:56:35 | × | pfurla_ quits (~pfurla@183.15.195.173.client.static.strong-in52.as13926.net) (Ping timeout: 268 seconds) |
| 2021-05-29 21:57:18 | <pavonia> | Well, that basically is reversing the evaluation order, no? |
| 2021-05-29 21:57:18 | × | ddellacosta quits (~ddellacos@89.46.62.25) (Ping timeout: 264 seconds) |
| 2021-05-29 21:57:25 | <dminuoso> | evaluation order? :) |
| 2021-05-29 21:57:31 | <dminuoso> | is unspecified in haskell |
| 2021-05-29 21:57:40 | × | __monty__ quits (~toonn@user/toonn) (Quit: leaving) |
| 2021-05-29 21:57:58 | <pavonia> | There's only one meaningful way to evaluate those terms |
| 2021-05-29 21:58:09 | <dminuoso> | Is there? |
| 2021-05-29 21:58:54 | <dminuoso> | Let's make two real examples: |
| 2021-05-29 21:58:54 | → | smatting joins (~stefan@p200300cd7715d60001a96e63c195d7c7.dip0.t-ipconnect.de) |
| 2021-05-29 21:59:04 | × | Bartosz quits (~textual@24.35.90.211) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2021-05-29 21:59:13 | <dminuoso> | foldr f z [1,2,3,4] = 1 `f` (2 `f` (3 `f` (4 `f` z))) |
| 2021-05-29 22:00:00 | <dminuoso> | foldl f z [1,2,3,4] = (((z `f` 1) `f` 2) `f` 3) `f` 4 |
| 2021-05-29 22:00:44 | <dminuoso> | If we set `f` to (+) we get |
| 2021-05-29 22:01:15 | justache | is now known as justBull |
| 2021-05-29 22:01:18 | <dminuoso> | Er, poor example |
| 2021-05-29 22:02:50 | <pavonia> | f will always be left- or right-associative, so the evaluation order should always be fixed given the implicit parentheses |
| 2021-05-29 22:03:04 | → | cstml joins (cstml@tilde.club) |
| 2021-05-29 22:03:04 | × | kmein quits (~weechat@static.173.83.99.88.clients.your-server.de) (Quit: ciao kakao) |
| 2021-05-29 22:03:25 | → | kmein joins (~weechat@static.173.83.99.88.clients.your-server.de) |
| 2021-05-29 22:03:49 | <dminuoso> | What do you mean by evaluation order, exactly? |
| 2021-05-29 22:03:54 | <dminuoso> | Consider setting `f` to (:) |
| 2021-05-29 22:03:56 | × | kmein quits (~weechat@static.173.83.99.88.clients.your-server.de) (Client Quit) |
| 2021-05-29 22:04:03 | <dminuoso> | Would you agree that you dont need the right hand side to work with the left hand side? |
| 2021-05-29 22:04:10 | → | kmein joins (~weechat@static.173.83.99.88.clients.your-server.de) |
| 2021-05-29 22:04:26 | <dminuoso> | If you set `f` to (:) and `z` to [], you get: |
| 2021-05-29 22:04:36 | <dminuoso> | 1 : (2 : (3 : (4 : []))) |
| 2021-05-29 22:04:55 | <dminuoso> | And indeed, I can prove this will *not* force the right hand side |
| 2021-05-29 22:05:09 | <dminuoso> | % take 10 $ foldr (:) [] [1..] |
| 2021-05-29 22:05:09 | <yahb> | dminuoso: [1,2,3,4,5,6,7,8,9,10] |
| 2021-05-29 22:05:31 | <dminuoso> | pavonia: If what you said was right, and this evaluated from right to left, this would have bottomed out |
| 2021-05-29 22:06:07 | × | smatting quits (~stefan@p200300cd7715d60001a96e63c195d7c7.dip0.t-ipconnect.de) (Ping timeout: 245 seconds) |
| 2021-05-29 22:06:09 | × | tromp quits (~textual@dhcp-077-249-230-040.chello.nl) (Quit: My iMac has gone to sleep. ZZZzzz…) |
| 2021-05-29 22:06:10 | <monochrom> | > foldr (&&) undefined (repeat False) |
| 2021-05-29 22:06:11 | <lambdabot> | False |
| 2021-05-29 22:07:45 | <monochrom> | If your model doesn't explain that, it's a wrong model. |
| 2021-05-29 22:08:05 | <monochrom> | If your model explains that but with lots of epicycles, it has lots of epicycles. |
| 2021-05-29 22:08:12 | × | favonia quits (~favonia@user/favonia) (Ping timeout: 245 seconds) |
| 2021-05-29 22:08:39 | ← | meltedbrain_y2k parts (~tekserf@45.83.220.218) () |
| 2021-05-29 22:10:46 | <pavonia> | Well, thanks. I'll play with the fold*M defintions |
| 2021-05-29 22:11:16 | → | ddellacosta joins (~ddellacos@89.46.62.76) |
| 2021-05-29 22:11:56 | → | favonia joins (~favonia@user/favonia) |
| 2021-05-29 22:12:00 | <hololeap> | dminuoso: hah, you picked an abelian monoid :p |
| 2021-05-29 22:13:03 | <hololeap> | (choosing (+) as your example) |
| 2021-05-29 22:13:14 | × | abhixec quits (~abhixec@c-67-169-139-16.hsd1.ca.comcast.net) (Ping timeout: 268 seconds) |
| 2021-05-29 22:13:35 | <dminuoso> | hololeap: It was a bad example for a different reason. |
| 2021-05-29 22:14:53 | <dminuoso> | The difference between foldr and foldl with (+) can be observed only indirectly |
| 2021-05-29 22:15:18 | <hololeap> | oh, true |
| 2021-05-29 22:15:34 | → | curiousgay joins (~AdminUser@178.217.208.8) |
| 2021-05-29 22:15:46 | <dminuoso> | one will cause a stack overflow, and the other will fill up your heap first. |
| 2021-05-29 22:16:02 | × | ddellacosta quits (~ddellacos@89.46.62.76) (Ping timeout: 252 seconds) |
| 2021-05-29 22:16:46 | <dminuoso> | And that's actually what pavonia was probably thinking about |
| 2021-05-29 22:17:40 | <dminuoso> | perhaps their mistake was not realizing that the function to foldr can itself return a lambda or be a data constructor |
| 2021-05-29 22:17:46 | × | kmein quits (~weechat@static.173.83.99.88.clients.your-server.de) (Quit: ciao kakao) |
| 2021-05-29 22:18:04 | → | kmein joins (~weechat@static.173.83.99.88.clients.your-server.de) |
| 2021-05-29 22:18:11 | <davean> | no, I don't think that explains the mistake |
| 2021-05-29 22:18:16 | <dminuoso> | mmm |
| 2021-05-29 22:18:34 | <davean> | consider if it doesn't look at an argument |
| 2021-05-29 22:18:49 | <dminuoso> | right |
| 2021-05-29 22:19:50 | × | kmein quits (~weechat@static.173.83.99.88.clients.your-server.de) (Changing host) |
| 2021-05-29 22:19:50 | → | kmein joins (~weechat@user/kmein) |
| 2021-05-29 22:19:50 | <pavonia> | What I'm trying to do is to run a `ST s ()` action on each element of a ByteString. I'm just unsure which of the two folds is the more efficient option in this case |
All times are in UTC.