Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,803,725 events total
2021-07-27 20:36:06 × jushur quits (~human@user/jushur) (Quit: ¯\_(ツ)_/¯)
2021-07-27 20:36:27 <Cale> But like, that's also true of the entire rest of the programming language, so I don't see it as a really big deal
2021-07-27 20:36:38 <dsal> lechner: peruse means you've seen something, but the original definition implies you studied it very carefully and the other meaning suggests you've only taken a cursory glance.
2021-07-27 20:36:44 <Cale> You're going to be introduced to return at some point, and you might've thought it meant something a bit different before then
2021-07-27 20:36:48 × chris_ quits (~chris@81.96.113.213) (Remote host closed the connection)
2021-07-27 20:36:50 alexfmpe[m] joins (~alexfmpem@2001:470:69fc:105::38ba)
2021-07-27 20:36:50 robertm joins (robertm@rojoma.com)
2021-07-27 20:37:01 <Cale> But I've never seen anyone get *really* stuck on it
2021-07-27 20:37:16 <Cale> once they're aware that "return v" is the no-op action that does nothing except return v
2021-07-27 20:37:23 <dsal> Cale: I don't think I fundamentally disagree with you. `return` doesn't confuse me that much, but only because I don't think of it as a word and instead immediately alias it to `pure` and move on.
2021-07-27 20:37:33 <dsal> But you suggest that it's important to *use* `return` and that part I don't understand.
2021-07-27 20:37:50 ukari joins (~ukari@user/ukari)
2021-07-27 20:38:31 <Cale> Well, the part about using return when appropriate is just that its type is a little more specific, and so the distinction of return vs. pure helps us know when we're really making use of a broader abstraction.
2021-07-27 20:38:37 <alexfmpe[m]> I could have sworn I had seen an util for folding two lists at once but am unable to find it, anyone know what I'm talking about?
2021-07-27 20:38:44 <dsal> But `return v` doesn't `return v` it just places a pure value inside the current Monad. i.e. `return = Just` or `return = Right` or whatever. It's an abstraction of a constructor, not any kind of flow control thing like the verb suggests.
2021-07-27 20:38:44 × amk quits (~amk@176.61.106.150) (Ping timeout: 255 seconds)
2021-07-27 20:38:57 <lechner> dsal: it's a super old rhetorical device: one morning, one night---a day. it describes the range between the edge cases
2021-07-27 20:38:59 <Cale> alexfmpe[m]: hmm... you mean like, folding through their zip?
2021-07-27 20:39:12 <Cale> alexfmpe[m]: Or it's supposed to do something different if one of them ends early?
2021-07-27 20:39:25 amk joins (~amk@176.61.106.150)
2021-07-27 20:39:35 <Cale> dsal: Well, it does
2021-07-27 20:39:50 <Cale> In the same way that when we have something like v <- x
2021-07-27 20:39:55 <alexfmpe[m]> cale: more of the later, as in the merge step of mergesort
2021-07-27 20:39:56 <Cale> The v is the value that x returned
2021-07-27 20:40:02 <Cale> So when you write v <- return 3
2021-07-27 20:40:05 <Cale> then v is 3
2021-07-27 20:40:11 <dsal> :t zipWith bimap
2021-07-27 20:40:13 <lambdabot> Bifunctor p => [a -> b] -> [c -> d] -> [p a c -> p b d]
2021-07-27 20:40:30 <alexfmpe[m]> dsal: "abstraction of a constructor" isn't at all how I would put it, take ZipList or Cont for instance
2021-07-27 20:40:55 <maerwald> dsal: I think `success` and `fail` would be reasonble shortcut names. `return` is more from the ASM days
2021-07-27 20:41:18 <Cale> I think of "return v" as meaning "the action which, when executed, produces v as its result"
2021-07-27 20:41:37 <dsal> Cale: I think I can at least parse that.
2021-07-27 20:41:55 <Cale> So return v is the action which... returns v
2021-07-27 20:42:10 <Cale> It doesn't mean "return from the caller immediately with v"
2021-07-27 20:42:12 <maerwald> `return` means `return to the address on the top of the stack`
2021-07-27 20:42:13 <dsal> I feel like it's a stretch, but I can at least accept it. :)
2021-07-27 20:42:23 <maerwald> for anything else, the word doesn't make any sense
2021-07-27 20:42:26 × neceve quits (~quassel@2a02:c7f:607e:d600:f762:20dd:304e:4b1f) (Ping timeout: 252 seconds)
2021-07-27 20:42:32 <Cale> I think it's *less* of a stretch than the traditional sense of return in programming
2021-07-27 20:42:52 <dsal> ...but why do you consider using `pure` for the same thing less desirable?
2021-07-27 20:42:52 <alexfmpe[m]> I dunno, every intuition besides `pure` being identity-ish (which exactly what the laws require), seems more of a trap to me
2021-07-27 20:43:17 <maerwald> Cale: "returning v" may make sense in rust, where you return ownership
2021-07-27 20:43:30 <dsal> alexfmpe[m]: Sure, sure. I don't mind traps as long as I can get back out of them.
2021-07-27 20:43:43 <maerwald> but in most languages you don't even have such a concept
2021-07-27 20:43:47 <alexfmpe[m]> I meant traps as in actually getting in the way
2021-07-27 20:43:48 <maerwald> no one owns anything
2021-07-27 20:43:56 <dsal> alexfmpe[m]: Yeah, I get the meaning.
2021-07-27 20:44:06 <deejaytee> I tend to use pure instead of return everywhere, since it prevents people unfamiliar with haskell for mistaking it for the return they know
2021-07-27 20:44:25 <alexfmpe[m]> I've hated the normal formulation of applicative/monad ever since I saw the monoidal and join/fmap based laws
2021-07-27 20:44:39 <dsal> My understanding of haskell is good enough that it's my go-to language for just about everything including just thinking of stuff. But if I ever have a completely intuitive understanding of all of it, I'll have to find something else.
2021-07-27 20:44:40 <deejaytee> admittedly a pretty weird use - nobody ever really reads my code anyways
2021-07-27 20:44:49 chris_ joins (~chris@81.96.113.213)
2021-07-27 20:44:51 <maerwald> deejaytee: I know that feeling
2021-07-27 20:44:54 <alexfmpe[m]> it's just...collapsing and mapping
2021-07-27 20:45:04 <alexfmpe[m]> trying to treat it as anything else is just going to confuse me
2021-07-27 20:46:16 acidjnk_new3 joins (~acidjnk@p200300d0c72b950729faca9193881d78.dip0.t-ipconnect.de)
2021-07-27 20:46:45 <Cale> alexfmpe[m]: foldr2 b l r z (x:xs) [] = foldr l z (x:xs); foldr2 b l r z [] (y:ys) = foldr r z (y:ys); foldr2 b l r z (x:xs) (y:ys) = b l r (foldr2 b l r z xs ys)
2021-07-27 20:46:48 <Cale> maybe?
2021-07-27 20:47:12 <Cale> There's probably something more general still...
2021-07-27 20:47:39 × eggplantade quits (~Eggplanta@108-201-191-115.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)
2021-07-27 20:47:48 <Cale> Actually, maybe it's saner to factor out the uses of foldr at the ends
2021-07-27 20:47:56 <alexfmpe[m]> oh hmm
2021-07-27 20:47:58 eggplantade joins (~Eggplanta@108-201-191-115.lightspeed.sntcca.sbcglobal.net)
2021-07-27 20:48:00 <alexfmpe[m]> not quite like that
2021-07-27 20:48:32 <Cale> (and I didn't handle the doubly empty case, I was going to generalise the (x:xs) pattern match...)
2021-07-27 20:48:33 <alexfmpe[m]> I'm basically gate-ing one of the lists against the other
2021-07-27 20:48:36 <alexfmpe[m]> like, whitelisting
2021-07-27 20:48:48 × fossdd quits (~fossdd@sourcehut/user/fossdd) (Ping timeout: 276 seconds)
2021-07-27 20:49:05 <Cale> Ohh... like, say to compute the intersection of sorted lists?
2021-07-27 20:49:12 fossdd joins (~fossdd@sourcehut/user/fossdd)
2021-07-27 20:49:30 <alexfmpe[m]> welll, almost whitelisting, I'm checking that a subsequence of one list matches is included in the other
2021-07-27 20:50:18 <alexfmpe[m]> I've done it manually, with normal pattern matching and recursion
2021-07-27 20:50:53 <Cale> Is the order important?
2021-07-27 20:51:14 <Cale> (Or could we pass to using e.g. Data.Set, which would be more efficient a lot of the time)
2021-07-27 20:51:29 <alexfmpe[m]> I'm not 100%, as it's been a while but I think so
2021-07-27 20:51:37 <alexfmpe[m]> otherwise, yeah, intersection
2021-07-27 20:52:03 × werneta quits (~werneta@70-142-214-115.lightspeed.irvnca.sbcglobal.net) (Remote host closed the connection)
2021-07-27 20:52:43 <alexfmpe[m]> oh, this might work https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-List.html#v:intersect
2021-07-27 20:53:22 <alexfmpe[m]> take the intersection and check it matches the original list I'm whitelisting against
2021-07-27 20:53:44 pschorf joins (~user@c-73-77-28-188.hsd1.tx.comcast.net)
2021-07-27 20:54:04 <dsal> :t fold . zipWith
2021-07-27 20:54:05 <lambdabot> Foldable ((->) [a]) => (a -> b -> c) -> [b] -> [c]
2021-07-27 20:54:09 <Cale> It could, but note that this thing only requires Eq, so there's no way it's anything cheaper than quadratic
2021-07-27 20:54:30 <alexfmpe[m]> bah
2021-07-27 20:54:45 <alexfmpe[m]> in my case I actually needed `intersectBy :: (a -> b -> Bool) -> [a] -> [b] -> [a]` or something
2021-07-27 20:54:59 <alexfmpe[m]> but `intersectBy` is `a -> a -> Bool` for some reaosn
2021-07-27 20:55:06 <alexfmpe[m]> and, yeah, quadratic
2021-07-27 20:55:25 <Cale> I'm sure I've written this higher order function before...
2021-07-27 20:55:28 werneta joins (~werneta@70-142-214-115.lightspeed.irvnca.sbcglobal.net)
2021-07-27 20:55:42 <Cale> that applies a function to know whether to walk down one list or the other
2021-07-27 20:55:51 <Cale> and produces results as it goes
2021-07-27 20:55:53 <dsal> :t \f l1 -> fold . zipWith (\a b -> f a b) l1
2021-07-27 20:55:55 <lambdabot> Monoid c => (t1 -> t2 -> c) -> [t1] -> [t2] -> c
2021-07-27 20:55:59 <dsal> Well that's kind of gross.
2021-07-27 20:56:06 <Cale> It's different from folding over the zip
2021-07-27 20:56:14 <alexfmpe[m]> well, this is assymetric, I always go down the whitelist one, and may or may not go down the whitelisted one depending on whether it matches
2021-07-27 20:56:26 <dsal> Yeah, sorry, I'm not actually aware of the topic here. Just was wondering about that.
2021-07-27 20:56:43 <alexfmpe[m]> I dunno, maybe I should fold the whitelist one, and have a pair as the accumulator
2021-07-27 20:57:17 <alexfmpe[m]> `(already-whitelisted, check-whether-whitelisted) :: ([a], [a])`
2021-07-27 20:58:01 × eggplantade quits (~Eggplanta@108-201-191-115.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection)

All times are in UTC.