Logs: liberachat/#haskell
| 2025-11-11 01:05:43 | × | Googulator65 quits (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) (Quit: Client closed) |
| 2025-11-11 01:05:50 | → | Googulator91 joins (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) |
| 2025-11-11 01:05:53 | × | Sidney quits (~Sidney@2600:4040:2678:9600:b1c4:ced3:242d:1252) (Ping timeout: 250 seconds) |
| 2025-11-11 01:07:16 | → | Sidney joins (~Sidney@2600:4040:2678:9600:b1c4:ced3:242d:1252) |
| 2025-11-11 01:10:50 | × | Googulator91 quits (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) (Quit: Client closed) |
| 2025-11-11 01:10:59 | → | Googulator91 joins (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) |
| 2025-11-11 01:15:37 | × | tabaqui quits (~tabaqui@167.71.80.236) (Ping timeout: 264 seconds) |
| 2025-11-11 01:15:42 | → | Googulator83 joins (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) |
| 2025-11-11 01:16:09 | × | Googulator91 quits (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) (Quit: Client closed) |
| 2025-11-11 01:18:55 | → | merijn joins (~merijn@host-vr.cgnat-g.v4.dfn.nl) |
| 2025-11-11 01:19:28 | <mange> | Sidney: You can use recursion, building up a hash table as you go. The two sum problem, for instance, could be like this: http://paste.debian.net/1405577/ (I'm using Map because it was easier, but you can see the idea). |
| 2025-11-11 01:20:26 | <mange> | The move zeros one you linked to is explicitly about mutating an array, so obviously you can't do that without mutation. |
| 2025-11-11 01:22:45 | × | DetourNetworkUK quits (DetourNetw@user/DetourNetworkUK) (Read error: Connection reset by peer) |
| 2025-11-11 01:22:47 | → | DetourNe- joins (DetourNetw@user/DetourNetworkUK) |
| 2025-11-11 01:23:26 | × | Starving_Drummer quits (~berke@user/Starving-Drummer:76786) (Remote host closed the connection) |
| 2025-11-11 01:23:58 | <mange> | Oh, wait, sorry, I misread your message. You don't want to use a hash table. That makes sense. |
| 2025-11-11 01:24:49 | × | Googulator83 quits (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) (Quit: Client closed) |
| 2025-11-11 01:25:04 | → | Googulator83 joins (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) |
| 2025-11-11 01:25:04 | DetourNe- | is now known as DetourNetworkUK |
| 2025-11-11 01:25:32 | × | Googulator83 quits (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) (Client Quit) |
| 2025-11-11 01:25:43 | → | Googulator83 joins (~Googulato@2a01-036d-0106-0180-8127-ba79-55a7-6f29.pool6.digikabel.hu) |
| 2025-11-11 01:25:53 | × | merijn quits (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 256 seconds) |
| 2025-11-11 01:28:17 | <int-e> | sorting can help with two-sum |
| 2025-11-11 01:30:36 | <int-e> | > let (xs,ys) = partition (/= 0) [0,1,0,3,12] in xs ++ ys -- yes it's not in-place, but whatever |
| 2025-11-11 01:30:37 | <lambdabot> | [1,3,12,0,0] |
| 2025-11-11 01:31:23 | × | spew quits (~spew@user/spew) (Quit: WeeChat 4.6.3) |
| 2025-11-11 01:37:42 | → | merijn joins (~merijn@host-vr.cgnat-g.v4.dfn.nl) |
| 2025-11-11 01:40:27 | <jreicher> | two-sum doesn't have to be in-place I think. So you can ignore the "array" part and just think in terms of lists. |
| 2025-11-11 01:40:43 | <monochrom> | partition is probably still constant-space and linear-time. |
| 2025-11-11 01:40:58 | <mange> | Sidney: still not in-place (because it would require changing the input), but this should solve the two-sum problem by iterating through the list in both directions: http://paste.debian.net/1405581/ |
| 2025-11-11 01:41:07 | <mange> | ... After sorting it, that is. |
| 2025-11-11 01:41:31 | <int-e> | jreicher: yes, but the code snippet was for move-zeroes |
| 2025-11-11 01:41:55 | × | merijn quits (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 240 seconds) |
| 2025-11-11 01:41:57 | × | gorignak quits (~gorignak@user/gorignak) (Quit: quit) |
| 2025-11-11 01:42:04 | <Sidney> | Okay, thank you for the help. |
| 2025-11-11 01:42:05 | <Sidney> | Regarding two-pointer questions: is it possible to use recursion to get a single pass with the left and right pointers as function parameters? |
| 2025-11-11 01:42:05 | <Sidney> | I tried to solve the "Best Time to Buy and Sell Stock" problem (https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/) using a fold to calculate the profit each day, but that resulted in O(n²) complexity because I needed to calculate the maximum value for the remainder of the collection. Lastly I have heard some people say |
| 2025-11-11 01:42:06 | <Sidney> | that some things are 'inherently stateful' so functional programming is not capable of solving the problem elegantly. Is that true? It seems arbitrary that a `for loop` is the only tool that can solve these problems compared behaviors in mathematics such as recursion but I am ignorant and would like to know what you have to say. |
| 2025-11-11 01:42:13 | → | gorignak joins (~gorignak@user/gorignak) |
| 2025-11-11 01:42:25 | <monochrom> | "in-place" is an over-specification. Externally you can only observe space growth or lack-of, not how it is achieved. |
| 2025-11-11 01:42:27 | <EvanR> | whether you are using explicit recursion or a folding combinator or whatever it's still stateful in spirit |
| 2025-11-11 01:42:51 | <int-e> | mange: well those indices are wrong, because sorting changes the order of things |
| 2025-11-11 01:42:52 | <EvanR> | actually "state" is heavily overloaded and can mean many things |
| 2025-11-11 01:43:11 | <int-e> | mange: reconstructing indices makes this a tad annoying |
| 2025-11-11 01:43:13 | <jreicher> | Sidney: coincidentally I recently watched this. https://youtu.be/QNM-njddhIw?t=970&si=tWEcEVmsr44nKlVs |
| 2025-11-11 01:43:19 | <EvanR> | Sidney, yeah, that's incorrect |
| 2025-11-11 01:43:27 | <mange> | Oh yeah, obviously! Thanks int-e. I'm not going to fix it, because I can't be bothered right now. |
| 2025-11-11 01:43:29 | <jreicher> | The middle of that section of the video covers something very similar to move-zeroes |
| 2025-11-11 01:43:45 | <int-e> | mange: That's okay :P |
| 2025-11-11 01:44:33 | <int-e> | mange: FWIW, I'd probably just search for the found elements in the original list. |
| 2025-11-11 01:44:56 | <int-e> | :t findIndex |
| 2025-11-11 01:44:57 | <lambdabot> | (a -> Bool) -> [a] -> Maybe Int |
| 2025-11-11 01:45:10 | <int-e> | :t elemIndex |
| 2025-11-11 01:45:12 | <lambdabot> | Eq a => a -> [a] -> Maybe Int |
| 2025-11-11 01:45:40 | <EvanR> | there's much less difference between mutating an array and updating a Map than you think there is. There much less difference between a recursive program and a for loop than you think there is |
| 2025-11-11 01:45:51 | <jreicher> | Sidney: In my opinion (and not everyone will agree with this I think) even if you write "statelessly", the computation is still stateful. That's never in doubt. A computer executes in the real world by changing state moment to moment. So the question is not whether you have state, but whether you have to write it explicitly or whether the language (Haskell) can figure it out for you. A lot of the time it can. |
| 2025-11-11 01:47:17 | × | gorignak quits (~gorignak@user/gorignak) (Quit: quit) |
| 2025-11-11 01:47:33 | → | gorignak joins (~gorignak@user/gorignak) |
| 2025-11-11 01:47:38 | <EvanR> | folding over a list of things using "a state" accomplishes the same thing as looping over the things and mutating variables |
| 2025-11-11 01:47:52 | <monochrom> | I feel like "there is no royal road" applies. How to think in French? By immersing in French for weeks, months, years. How to think in Japanese? By immersing in Japanese for weeks, months, years. How to think in Haskell? By immersing... you get my point. |
| 2025-11-11 01:47:56 | <EvanR> | sometimes it's more convenient sometimes it's not |
| 2025-11-11 01:48:30 | <EvanR> | yes keep writing programs (and reading programs) |
| 2025-11-11 01:48:57 | <monochrom> | But I do tell my students: Think of Haskell functions as math functions, not C "functions". Think algebra. |
| 2025-11-11 01:50:05 | <EvanR> | ^ this very good advice has no effect on people who hate math |
| 2025-11-11 01:50:38 | <monochrom> | Oh if you hate math, there is nothing in Haskell for you. |
| 2025-11-11 01:50:45 | <EvanR> | though maybe subjecting them to enough haskell gives them a better appreciation for mathematical thinking |
| 2025-11-11 01:51:12 | → | merijn joins (~merijn@host-vr.cgnat-g.v4.dfn.nl) |
| 2025-11-11 01:51:56 | int-e | wonders when he last used the term "procedure" for an imperative "function". |
| 2025-11-11 01:51:56 | × | synchromesh quits (~john@2406:5a00:2412:2c00:c5a6:321c:259:76f2) (Read error: Connection reset by peer) |
| 2025-11-11 01:52:17 | <monochrom> | We should do that more! |
| 2025-11-11 01:52:27 | <int-e> | (A Pascal remnant, though Pascal's distinction based on whether a function returns a value or not is odd too.) |
| 2025-11-11 01:52:37 | × | gorignak quits (~gorignak@user/gorignak) (Quit: quit) |
| 2025-11-11 01:52:51 | <monochrom> | If foo :: IO Int, what do you call foo, i.e., what is the name of the kind of things like foo? Answer: procedure. |
| 2025-11-11 01:52:52 | → | synchromesh joins (~john@2406:5a00:2412:2c00:ed84:4ebe:de81:99a2) |
| 2025-11-11 01:52:54 | → | gorignak joins (~gorignak@user/gorignak) |
| 2025-11-11 01:53:07 | <int-e> | And sorry, I believe "function" is too ingrained in my brain by now. |
| 2025-11-11 01:53:18 | <int-e> | It's an overloaded concept, one of many. |
| 2025-11-11 01:54:00 | <monochrom> | The Algol people got it wrong in the first place. They said "side-effecting functions" [sic], just because there is a "return value". |
| 2025-11-11 01:54:56 | <EvanR> | returning a value was undervalued all the way even until ruby |
| 2025-11-11 01:55:07 | <monochrom> | If the null pointer was a billion-dollar mistake, I invoke Sapir-Worf and call that a priceless mistake. |
| 2025-11-11 01:55:09 | <EvanR> | so many forms in ruby return nothing useful and so can't be combined |
| 2025-11-11 01:55:34 | <int-e> | EvanR: can't wait for the paper on the trillion-dollar mistake in about 50 years |
| 2025-11-11 01:55:53 | <EvanR> | the 1 TRILLION dollar mistake *crowd laughs* |
| 2025-11-11 01:56:30 | × | merijn quits (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 256 seconds) |
| 2025-11-11 01:56:41 | <int-e> | (adjusted for inflation relative to 2025) |
| 2025-11-11 01:56:59 | <int-e> | (and possibly new currencies) |
| 2025-11-11 01:57:23 | <EvanR> | or old currencies, because the euro was abandoned |
| 2025-11-11 02:01:00 | <jreicher> | monochrom: I think Haskell functions are a third kind of function. Math functions are often (infinite) sets. Haskell functions describe a construction of the set, which is a little. But they do it declarative, which is why they're not like C functions. |
| 2025-11-11 02:01:11 | <jreicher> | ...a little different... |
| 2025-11-11 02:01:43 | × | otto_s quits (~user@p4ff2712e.dip0.t-ipconnect.de) (Ping timeout: 240 seconds) |
| 2025-11-11 02:01:46 | <monochrom> | About many ruby forms can't be combined. Yeah even the javascript community discovered long ago that if an object method returns the object itself, then you can write obj.method1().method2().method3(), it's pretty neat. |
| 2025-11-11 02:03:37 | <int-e> | jreicher: I think the point is that math functions are a better model for what Haskell functions are than C functions. |
| 2025-11-11 02:03:41 | → | otto_s joins (~user@p4ff27119.dip0.t-ipconnect.de) |
| 2025-11-11 02:04:13 | <int-e> | (they do a decent job capturing purity) |
| 2025-11-11 02:05:20 | <jreicher> | No argument with that, but there are still problems with the math model. You can define a non-computable function mathematically. |
| 2025-11-11 02:05:43 | <int-e> | I didn't say that you're wrong (you aren't) |
| 2025-11-11 02:05:57 | <monochrom> | No worries. I say "think math functions, algebra" to students who are too used to imperative thinking. They already can't escaping thinking of recipes for explicit construction. So telling them "like algebra" will get the right result. |
| 2025-11-11 02:06:01 | <int-e> | monochrom's teaching this stuff |
| 2025-11-11 02:06:30 | <jreicher> | monochrom: do you teach Haskell, or some of the other languages and/or lambda calculus/semantics? |
| 2025-11-11 02:06:53 | <int-e> | And it's common that you use flawed analogies for new concepts when teaching. |
All times are in UTC.