Post APfrN6IBah7N9QqPZ2 by billstclair@impeccable.social
(DIR) More posts by billstclair@impeccable.social
(DIR) Post #APfhcvXaKkxAtgxHSC by hungryjoe@functional.cafe
2022-11-16T17:46:18Z
0 likes, 0 repeats
You can think of the `l` and `r` in `foldl` and `foldr` as meaning "applying a left-associative/right-associative operation over the values in a list"? Right?This has only just clicked for me today
(DIR) Post #APfhcwI1Y66HDigMq0 by janiczek@functional.cafe
2022-11-16T17:50:20Z
0 likes, 0 repeats
@hungryjoe I loved this talk about folds: https://www.youtube.com/watch?v=dSMB3rsufC8Haven't really thought about folds as replacing constructors before that.
(DIR) Post #APfhcwnDg73OmTHHSi by hungryjoe@functional.cafe
2022-11-16T18:00:08Z
0 likes, 0 repeats
@janiczek So the "catamorphisms as replacing constructors with functions" is a familiar concept to me (I've done my time in the Recursion Scheme mines)I also wrote an SO answer about why the order of arguments in foldl/r is what it is:https://stackoverflow.com/questions/69252611/confused-about-parameters-in-haskell-lambdas/69252887#69252887But "the l/r stands for the associativity of the aggregation function" has literally only just clicked for me now
(DIR) Post #APfhcx9uJlCZuptOpE by janiczek@functional.cafe
2022-11-16T18:09:31Z
1 likes, 0 repeats
@hungryjoeRecursion Scheme minesYou have my condolences! ⛏️🏔️
(DIR) Post #APfhcxDS6a2O5pYELo by hungryjoe@functional.cafe
2022-11-16T17:47:11Z
0 likes, 0 repeats
On the offchance that I've got this backwards, in which case: that doesn't make sense, whoops, ignore me
(DIR) Post #APfhcxhaIY8lbHeIJk by hungryjoe@functional.cafe
2022-11-16T18:10:25Z
0 likes, 0 repeats
@janiczek It's fun down thereBut also very dark and deep
(DIR) Post #APfhcyk6QfkUpNposi by hungryjoe@functional.cafe
2022-11-16T18:12:07Z
0 likes, 0 repeats
@janiczek I've shown you the "marcidomorphism" (Blobfish Morphism) in the work codebase, right?(it predates me)
(DIR) Post #APfhczJuHYOAcQaPgm by janiczek@functional.cafe
2022-11-16T19:42:31Z
0 likes, 0 repeats
@hungryjoe Uh, not yet. Thankfully I will be offline for the rest of the week 😂Recursion schemes look to me like a great puzzle for cold winter evenings, but whenever I tried to use them in the elm-in-elm codebase (so no HKTs) I felt lost very very quick. I understand how some of it gives better code separation, but I feel like it's not for me currently.Anecdotally there are about three people on the Elm Slack who understand, play with and evangelize them 😁
(DIR) Post #APfhcziMobxFqI1woa by billstclair@impeccable.social
2022-11-16T19:57:15.704863Z
0 likes, 0 repeats
@janiczek @hungryjoe Recursion is the ONLY way to do looping in Elm. Fortunately, the well-debugged map and fold functions are usually sufficient. But I sometimes write a tail-recursive function, usually named “loop”. You have to be careful, though. JavaScript doesn’t have tail-recursive function calls, so the functions have to be in the same local scope for the compiler to figure out that it can do goto instead of function call.
(DIR) Post #APfrN5rFCrZDnsEtZQ by janiczek@functional.cafe
2022-11-16T20:34:44Z
0 likes, 0 repeats
@billstclair @hungryjoe Recursion (tail or not, mutual or not) is fine and understood.Recursion schemes are a whole another beast though :)
(DIR) Post #APfrN6IBah7N9QqPZ2 by billstclair@impeccable.social
2022-11-16T21:46:28.449079Z
0 likes, 0 repeats
@janiczek @hungryjoe My bad. I have no idea then what is meant by “recursion scheme”.
(DIR) Post #APfuADOgAEflHfQeIa by janiczek@functional.cafe
2022-11-16T22:08:32Z
0 likes, 0 repeats
@billstclair @hungryjoe I am too big of an amateur to give a comprehensive summary but basically they're functions generalizing recursion patterns.One for folds (catamorphism as in "cata"strophe, collapsing N values into one)One for unfolds - building N values from one (anamorphism as in "ana"bolics, building up muscles or something) -- the clearest example I have of that in Elm is Ilias' Tree.unfold, creating a tree from an initial value. They're more useful in Haskell where you can build infinite sequences based on previous items etc.There are some more for various combinations of "what do I want to hold while folding" (current item, whole history so far, etc.). It's a whole zoo! And for me the main question when looking at these is: Why bother 😁
(DIR) Post #APfuAE1fpFrfEbfn4y by billstclair@impeccable.social
2022-11-16T22:17:45.809312Z
0 likes, 0 repeats
@janiczek @hungryjoe Indeed. If an existing fold or map isn't a good match for what I need to do, I just write something. Problem solved. No need for a framework.