Logs: freenode/#haskell
| 2021-03-12 20:32:21 | × | arrowsvc_ quits (~arr@2.93.163.35) (Ping timeout: 264 seconds) |
| 2021-03-12 20:32:26 | × | heatsink quits (~heatsink@2600:1700:bef1:5e10:c79:3d13:d977:c947) (Ping timeout: 264 seconds) |
| 2021-03-12 20:33:40 | <hololeap> | sparsity: many people need to nail things down to a concrete example (like, why would i ever use this) before they can get a mental model of the problem |
| 2021-03-12 20:33:42 | × | geekosaur quits (82650c7a@130.101.12.122) (Ping timeout: 240 seconds) |
| 2021-03-12 20:34:19 | <sparsity> | the idea is that the comonad for a pointer should be immidiate from an implementation of Shaped, ie writing geti and seti |
| 2021-03-12 20:34:27 | × | Franciman quits (~francesco@host-82-49-79-189.retail.telecomitalia.it) (Quit: Leaving) |
| 2021-03-12 20:34:36 | <hololeap> | but why would i ever use this? |
| 2021-03-12 20:34:39 | <sparsity> | it extends over get and set, as generics for pattern matching cons |
| 2021-03-12 20:34:57 | <sparsity> | oh, you need the comonad for doing convolutions among other things |
| 2021-03-12 20:35:46 | → | rj joins (~x@gateway/tor-sasl/rj) |
| 2021-03-12 20:36:01 | <sparsity> | the pointer is set up as a zipper on a tree, the nested thing from the comonad is the pointer where each value in the container is a copy of the whole container with pointer to that value |
| 2021-03-12 20:36:12 | <hololeap> | why are you going to use it? is it purely theoretical or are you trying to create something will actually be used? |
| 2021-03-12 20:36:28 | <sparsity> | convolutions are ubiquitous in scientific computing |
| 2021-03-12 20:36:49 | → | Mrbuck joins (~Mrbuck@gateway/tor-sasl/mrbuck) |
| 2021-03-12 20:36:51 | <sparsity> | eg for covnets or finite difference schemes for fluid solvers |
| 2021-03-12 20:37:09 | → | Franciman joins (~francesco@host-82-49-79-189.retail.telecomitalia.it) |
| 2021-03-12 20:37:23 | <sparsity> | i want convolutions on graphs for implementing message passing algorithms |
| 2021-03-12 20:37:54 | <sparsity> | but have trouble syntactically explicating cyclic references |
| 2021-03-12 20:38:08 | <hololeap> | ok, that's still way over my head, but thanks for pinning it down. i'm sure that will help others help you |
| 2021-03-12 20:38:18 | <sparsity> | cheers |
| 2021-03-12 20:38:51 | <dmj`> | Had a haskell interview today, only question I asked was, "what's wrong with this code: avg xs = sum xs / length xs" |
| 2021-03-12 20:39:20 | <koz_> | dmj`: That it traverses the list twice or something? |
| 2021-03-12 20:39:33 | <Uniaika> | dmj`: it's not a weighted sum |
| 2021-03-12 20:39:34 | <Uniaika> | :P |
| 2021-03-12 20:39:40 | <dmj`> | koz_: that's one of a few things yes, can you spot more problems? |
| 2021-03-12 20:39:50 | <koz_> | dmj`: Yeah, it's monomorphic to Int. |
| 2021-03-12 20:39:56 | <Uniaika> | maybe the now-former laziness of sum? |
| 2021-03-12 20:39:58 | <koz_> | (which means it will probably not give the answer you think) |
| 2021-03-12 20:40:10 | <dmj`> | koz_: yes, needs a fromIntegral in there on the call to length |
| 2021-03-12 20:40:17 | <dmj`> | nice |
| 2021-03-12 20:40:25 | <koz_> | Even with that, it's _still_ not really poly enough. |
| 2021-03-12 20:40:39 | <dmj`> | koz_: just assume it's [Double] -> Double |
| 2021-03-12 20:40:42 | → | geekosaur joins (82650c7a@130.101.12.122) |
| 2021-03-12 20:40:43 | <koz_> | Since now you're fixed to (Integral a) => a which is probably _still_ not gonna give you the answer you think. |
| 2021-03-12 20:41:02 | <koz_> | If it's [Double] -> Double, you're fuxxored by IEEE754. |
| 2021-03-12 20:41:06 | <dmj`> | koz_: (/) ensures its not Integral |
| 2021-03-12 20:41:09 | <koz_> | Because floats are special. |
| 2021-03-12 20:41:28 | <dmj`> | koz_: ok tell me what the heap looks like |
| 2021-03-12 20:41:38 | × | ubert1 quits (~Thunderbi@p200300ecdf25d9cae6b318fffe838f33.dip0.t-ipconnect.de) (Ping timeout: 260 seconds) |
| 2021-03-12 20:41:39 | <koz_> | dmj`: That's outside of my realm of knowledge. |
| 2021-03-12 20:41:40 | <Uniaika> | yeah I think it should have been 'sum' xs `div` length xs' ? |
| 2021-03-12 20:41:50 | <koz_> | Haskell perf is something I don't know enough about. |
| 2021-03-12 20:41:57 | <koz_> | Uniaika: That's wrong answer territory. |
| 2021-03-12 20:42:22 | <Uniaika> | dangit |
| 2021-03-12 20:42:23 | <dmj`> | koz_: that's very common I'd say |
| 2021-03-12 20:42:36 | <dmj`> | koz_: this code, believe it or not, causes heap exhaustion for sufficiently large xs |
| 2021-03-12 20:42:37 | <koz_> | dmj`: Yeah, fair enough, it's not straightforward. |
| 2021-03-12 20:42:46 | <koz_> | dmj`: Is it due to laziness of sum? |
| 2021-03-12 20:42:48 | <dmj`> | koz_: well it shows me a deeper understanding |
| 2021-03-12 20:43:09 | <dmj`> | koz_: no, not entirely, you were right about the double pass over xs, but what does that mean from the heap's perspective? |
| 2021-03-12 20:43:21 | <koz_> | dmj`: Yeah, that's absolutely fair. I'm just being honest about waht I do or don't know. |
| 2021-03-12 20:43:25 | <koz_> | And in this case, I don't know. |
| 2021-03-12 20:43:31 | Uniaika | is pretty relieved they didn't interview with dmj` |
| 2021-03-12 20:43:34 | <koz_> | I would avoid it just for the double-pass reasons if nothing else. |
| 2021-03-12 20:43:52 | <hololeap> | dmj`: it holds the entire list in memory because it is going to pass over it twice? |
| 2021-03-12 20:43:54 | <geekosaur> | xs is kept live through the whole computation instead of being consumed as it goes along |
| 2021-03-12 20:43:58 | <dmj`> | koz_: the call to length forces the entire spine of the list in memory |
| 2021-03-12 20:44:01 | <dmj`> | hololeap: now we're talking |
| 2021-03-12 20:44:07 | <koz_> | Ah, I see. |
| 2021-03-12 20:44:09 | <dmj`> | geekosaur: bingo |
| 2021-03-12 20:44:11 | <koz_> | TIL. |
| 2021-03-12 20:44:34 | <dmj`> | koz_: there is one final problem with the code, along with lack of `fromIntegral`, lack of a type signature, heap exhaustion |
| 2021-03-12 20:44:50 | <dmj`> | koz_: can you spot it |
| 2021-03-12 20:44:51 | <koz_> | dmj`: OK, what's that? |
| 2021-03-12 20:44:53 | <koz_> | No. |
| 2021-03-12 20:45:04 | <dmj`> | koz_: what is length [] ? |
| 2021-03-12 20:45:12 | <koz_> | Ah, lol. |
| 2021-03-12 20:45:15 | <dmj`> | division by zero |
| 2021-03-12 20:45:17 | <koz_> | Nice one, should have spotted that. |
| 2021-03-12 20:45:33 | <dmj`> | Uniaika: just because someone doesn't spot all of it doesn't mean they're disqualified |
| 2021-03-12 20:46:04 | <hololeap> | dmj`: good job. that's pretty clever. |
| 2021-03-12 20:46:11 | <dmj`> | But it shows that you've some familiarity with Haskell's convoluted Numerical hierarchy, you have some knowledge of laziness, the heap and call by need. You have a keen eye for exceptions. |
| 2021-03-12 20:46:24 | <dmj`> | hololeap: thanks :) |
| 2021-03-12 20:46:42 | <hololeap> | it deceives with its apparent simplicity |
| 2021-03-12 20:46:44 | <Uniaika> | dmj`: I don't know man, I'm just a junior web developer :P |
| 2021-03-12 20:46:45 | <dmj`> | Also, I didn't make this up ! It's the final chapter of Real World Haskell :P that apparently nobody read :) |
| 2021-03-12 20:46:55 | Uniaika | goes back to making this goddamn webapp |
| 2021-03-12 20:47:11 | <dmj`> | hololeap: yes ! 99% of the time Haskell people resort to a strict eval way of thinking, but this is one of those 1%'ers of the time you can't do that, and you get punished. |
| 2021-03-12 20:47:48 | <Gurkenglas> | Aha! The counterexample to the lub library I wanted to construct yesterday relied on an imagined rewrite rule "fix f `lub` fix g ~> fix (f `lub` g)", which rewrite rule would increase definedness. Just undefined `lub` fix (fmap (const ())) is Just hangs, but fix (const (Just undefined) `lub` fmap (const ())) is Just (). |
| 2021-03-12 20:47:52 | <dmj`> | hololeap: avg xs = uncurry (/) $ foldl (\(sum',len') n -> (sum' + n, len' + 1)) (0,0) xs |
| 2021-03-12 20:48:02 | <dmj`> | it's the difference between 98% time spent in GC and 0% in GC |
| 2021-03-12 20:48:37 | × | knupfer quits (~Thunderbi@200116b82c66870055c2ea10e2e0e610.dip.versatel-1u1.de) (Ping timeout: 260 seconds) |
| 2021-03-12 20:48:51 | <hololeap> | wouldn't foldl' be better there? |
| 2021-03-12 20:49:17 | <Uniaika> | on arbitrary Foldables, no, but on lists yes |
| 2021-03-12 20:49:38 | <dmj`> | hololeap: you'd need more becuase foldl' will force the tuple to WHNF and won't stop thunk build up within the accumulators |
| 2021-03-12 20:50:06 | <dmj`> | hololeap: I did +RTS -s -RTS on both, and GHC is able to optimize it away somehow such that you only need foldl and no bang patterns (when compiling with -O2) |
| 2021-03-12 20:50:15 | <hololeap> | hm ok makes sense |
| 2021-03-12 20:50:21 | × | joebobjoe quits (~joebobjoe@unaffiliated/joebobjoe) (Ping timeout: 264 seconds) |
| 2021-03-12 20:50:44 | <dmj`> | hololeap: that's another classic space leak, storing a boxed tuple in an IORef, modifying it strictly but still allowing for thunk build up |
| 2021-03-12 20:50:54 | <dmj`> | of the values inside the tuple |
| 2021-03-12 20:51:10 | <dmj`> | That's why a strict data type is better data StrictTuple a b = StrictTuple !a !b |
| 2021-03-12 20:51:12 | × | jess quits (jess@freenode/staff/jess) (Remote host closed the connection) |
| 2021-03-12 20:51:19 | <dmj`> | then you don't have to worry about bangs |
| 2021-03-12 20:51:40 | → | j joins (jess@freenode/staff/jess) |
| 2021-03-12 20:52:16 | <dmj`> | During the naive avg there ends up being nothing to GC but the rapid allocations force the GC to run anyways. The GC threshold is hit, it goes back to allocating, more GC w/o collecting, until heap exhaustion |
| 2021-03-12 20:52:34 | × | crobbins quits (~crobbins@2601:2c1:200:ec50:2da1:91bc:2113:a3e2) (Remote host closed the connection) |
| 2021-03-12 20:53:13 | → | crobbins joins (~crobbins@2601:2c1:200:ec50:c8cd:d394:be82:ebad) |
| 2021-03-12 20:54:59 | × | danvet quits (~Daniel@2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa) (Ping timeout: 272 seconds) |
| 2021-03-12 20:55:16 | × | j quits (jess@freenode/staff/jess) (Quit: K-Lined) |
| 2021-03-12 20:55:36 | → | Lycurgus joins (~niemand@98.4.114.199) |
All times are in UTC.