Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→
Page 1 .. 832 833 834 835 836 837 838 839 840 841 842 .. 18024
1,802,386 events total
2021-07-07 06:37:49 <dminuoso> kammka: By the way, this intuition holds for *all* foldables, if we implicitly go through toListOf first.
2021-07-07 06:38:26 ahdyt joins (~ahdyt@103.105.28.181)
2021-07-07 06:39:46 aman joins (~aman@user/aman)
2021-07-07 06:40:51 kammka45 joins (~kammka@188.27.129.10)
2021-07-07 06:41:43 kammka55 joins (~kammka@188.27.129.10)
2021-07-07 06:42:39 <kammka55> dminuoso: doesn't it behave differently for tuples , for example? foldr (+) 1 (2,3) seems to disregard the first element of the pair
2021-07-07 06:42:52 <dminuoso> Let's entertain this train of thought:
2021-07-07 06:42:55 <dminuoso> % :t foldr
2021-07-07 06:42:56 <yahb> dminuoso: forall {t :: * -> *} {a} {b}. Foldable t => (a -> b -> b) -> b -> t a -> b
2021-07-07 06:43:25 <dminuoso> kammka55: Stare at this type signature, and tell me what you'd set for `t` in the above.
2021-07-07 06:43:28 × kammka quits (~kammka@188.27.129.10) (Ping timeout: 246 seconds)
2021-07-07 06:44:08 <dminuoso> Or
2021-07-07 06:44:13 <dminuoso> No, let's actually go with my claim.
2021-07-07 06:44:16 <dminuoso> 08:37:49 dminuoso | kammka: By the way, this intuition holds for *all* foldables, if we implicitly go through toListOf first.
2021-07-07 06:44:22 <dminuoso> % toListOf (1,2)
2021-07-07 06:44:22 <yahb> dminuoso: ; <interactive>:131:10: error:; * Couldn't match type: (a0, b0); with: (a -> Const (Endo [a]) a) -> s -> Const (Endo [a]) s; Expected: Getting (Endo [a]) s a; Actual: (a0, b0); * In the first argument of `toListOf', namely `(1, 2)'; In the expression: toListOf (1, 2); In an equation for `it': it = toListOf (1, 2); * Relevant bindings include it ::
2021-07-07 06:44:34 <dminuoso> % toList (1,2)
2021-07-07 06:44:35 <yahb> dminuoso: [2]
2021-07-07 06:44:41 <dminuoso> kammka55: Yeah I know, this is unexpected.
2021-07-07 06:45:13 × kammka45 quits (~kammka@188.27.129.10) (Ping timeout: 246 seconds)
2021-07-07 06:45:19 yauhsien joins (~yauhsien@61-231-39-135.dynamic-ip.hinet.net)
2021-07-07 06:46:30 <kammka55> dminuoso: I need to look up that function first- unfortunately I don't know the type of that? Or it should take the tuple and convert it to a list?
2021-07-07 06:46:38 <dminuoso> % :t toList
2021-07-07 06:46:38 <yahb> dminuoso: forall {t :: * -> *} {a}. Foldable t => t a -> [a]
2021-07-07 06:47:14 dunkeln_ joins (~dunkeln@188.70.10.207)
2021-07-07 06:47:20 <dminuoso> Let's assume that (1,2) :: (Int, Int) - in prefix notation that is: (1,2) :: (,) Int Int
2021-07-07 06:47:33 <dminuoso> % :t foldr
2021-07-07 06:47:33 <yahb> dminuoso: forall {t :: * -> *} {a} {b}. Foldable t => (a -> b -> b) -> b -> t a -> b
2021-07-07 06:47:52 <dminuoso> The only way this will work out, is if we set `t ~ (,) Int` and `a ~ Int`
2021-07-07 06:48:20 <dminuoso> Informally you can already see here, that the first element type is not considered part of the "content" here.
2021-07-07 06:48:40 <dminuoso> We could also use (Char, Int) here.
2021-07-07 06:49:01 <dminuoso> Informally 2-tuples are treated as singleton lists of the second element (and the first element is just some sort of tag)
2021-07-07 06:49:29 <dminuoso> Its debatable whether this instance is useful or perhaps even misleading, but it's the only possible implementation...
2021-07-07 06:49:46 × sayola1 quits (~vekto@dslb-088-078-152-192.088.078.pools.vodafone-ip.de) (Quit: Leaving.)
2021-07-07 06:50:03 sayola joins (~vekto@dslb-088-078-152-192.088.078.pools.vodafone-ip.de)
2021-07-07 06:50:06 × yauhsien quits (~yauhsien@61-231-39-135.dynamic-ip.hinet.net) (Ping timeout: 272 seconds)
2021-07-07 06:52:43 kammka joins (~kammka@188.27.129.10)
2021-07-07 06:52:50 <kammka> dminuoso: I always replaced t a with [a] in my mind. So in reality t stand for the data constructor? [] for lists and , for tuples?
2021-07-07 06:53:05 <dibblego> [] and (a,)
2021-07-07 06:53:14 <kammka> Oh I see it now
2021-07-07 06:53:16 × ahdyt quits (~ahdyt@103.105.28.181) (Ping timeout: 246 seconds)
2021-07-07 06:53:19 <dibblego> @kind Foldable
2021-07-07 06:53:20 <lambdabot> (* -> *) -> Constraint
2021-07-07 06:53:29 <dminuoso> kammka: a type constructor! :)
2021-07-07 06:54:35 <dminuoso> kammka: [T] can also be written as `[] T`, so if you then line it up with `t a`, it should be obvious what happens.
2021-07-07 06:55:07 <dminuoso> So here `[]` (not at the value-level, but at the type-level) is a proper type constructor.
2021-07-07 06:55:25 <dminuoso> We can think of `[T]` as just fancy syntax for what could have been `List T` instead
2021-07-07 06:55:52 <kammka> Mhm, I see
2021-07-07 06:56:19 × welterde quits (welterde@thinkbase.srv.welterde.de) (Quit: WeeChat 3.0.1)
2021-07-07 06:56:25 × kammka55 quits (~kammka@188.27.129.10) (Ping timeout: 246 seconds)
2021-07-07 06:56:27 welterde joins (welterde@thinkbase.srv.welterde.de)
2021-07-07 06:57:04 fendor joins (~fendor@178.165.171.166.wireless.dyn.drei.com)
2021-07-07 06:57:17 <shachaf> dminuoso: But foldl *doesn't* replace (:) and [] with functions.
2021-07-07 06:57:19 <dminuoso> kammka: Similarly for the type (again, not value level!) (S, T), which can also be written as `(,) S T`, and because type-level application like value level application is left-associative, you get:
2021-07-07 06:57:49 <shachaf> It does all sorts of computation. That's why you gotta know about foldl' and all these things if you use it.
2021-07-07 06:58:48 <dibblego> foldr does, foldl does other things
2021-07-07 06:59:19 <shachaf> foldr is special in that it does the thing you said (some people would say it's initial). Other "folds" on lists don't.
2021-07-07 06:59:36 kammka38 joins (~kammka@188.27.129.10)
2021-07-07 06:59:51 × lavaman quits (~lavaman@98.38.249.169) (Remote host closed the connection)
2021-07-07 07:00:15 <dminuoso> shachaf: I think it's still a good first approximation to get acquainted with foldr/foldl. But you're right that due to strictness there should be a note that Im telling a simplified lie.
2021-07-07 07:00:27 hatz_ is now known as Hatz_
2021-07-07 07:00:56 <dibblego> I do not believe it is a helpful lie.
2021-07-07 07:01:30 × ptr_frac7al quits (~longlong@user/ptr-frac7al/x-0038398) (Ping timeout: 272 seconds)
2021-07-07 07:02:45 <dminuoso> dibblego: Given that I provided concrete examples of what foldl does to a list, I disagree. *shrugs*
2021-07-07 07:03:00 <shachaf> It's a good thing to know about foldr, and you can certainly point out that foldl f z [a,b,c] = ((z `f` a) `f` b) `f` c
2021-07-07 07:03:04 × kammka quits (~kammka@188.27.129.10) (Ping timeout: 246 seconds)
2021-07-07 07:03:35 <dibblego> here is a good measure of a helpful lie: the benefits of what can now be done because of the lie, outweight the effort to require to not lie
2021-07-07 07:03:40 <dminuoso> But I'll take your hint and re-think whether I can find a better formulation of it.
2021-07-07 07:03:59 <dibblego> in this case, the benefits are at least small — possibly none (I cannot think of any), and the effort required to not lie is less than lying anyway
2021-07-07 07:04:43 <dibblego> foldl f z list does a loop; this one: { var r = z; foreach (el in list) { r = f r el }; return r }
2021-07-07 07:05:02 <dibblego> that was a lie; but it is helpful, because the analogy is dead accurate
2021-07-07 07:05:16 × dunkeln_ quits (~dunkeln@188.70.10.207) (Ping timeout: 246 seconds)
2021-07-07 07:05:31 <dibblego> "foldl replaces constructors" is a lie, and now you cannot do anything useful because of it (since it's not accurate, even as an analogy)
2021-07-07 07:06:57 <dibblego> I've left off "the effort required to now correct the lie", but: it is pretty big ime
2021-07-07 07:09:13 cfricke joins (~cfricke@user/cfricke)
2021-07-07 07:10:00 Obo joins (~roberto@70.pool90-171-81.dynamic.orange.es)
2021-07-07 07:10:26 × Erutuon quits (~Erutuon@user/erutuon) (Ping timeout: 252 seconds)
2021-07-07 07:12:33 Schrostfutz joins (~Schrostfu@schettlerdck.tkn.tu-berlin.de)
2021-07-07 07:18:34 × tzh quits (~tzh@c-24-21-73-154.hsd1.wa.comcast.net) (Quit: zzz)
2021-07-07 07:18:56 × adanwan quits (~adanwan@gateway/tor-sasl/adanwan) (Remote host closed the connection)
2021-07-07 07:19:10 adanwan joins (~adanwan@gateway/tor-sasl/adanwan)
2021-07-07 07:24:18 × juhp quits (~juhp@128.106.188.66) (Ping timeout: 252 seconds)
2021-07-07 07:25:23 ptr_frac7al joins (~longlong@user/ptr-frac7al/x-0038398)
2021-07-07 07:25:30 nschoe joins (~quassel@178.251.84.79)
2021-07-07 07:26:44 <DigitalKiwi> .glirclogs/#mostlyabsurd/2019-06-27.log:[12:10:24] <DigitalKiwi> is this a bad mnemonic: foldLeft/foldl => FL => For Loop; foldRight/foldr => fR => constructor Replacement
2021-07-07 07:27:04 andreabedini joins (~andreabed@8s8kj6nms09jvtyb2xjc.ip6.superloop.com)
2021-07-07 07:27:17 biberu joins (~biberu@user/biberu)
2021-07-07 07:28:17 mikoto-chan joins (~mikoto-ch@ip-213-49-189-31.dsl.scarlet.be)
2021-07-07 07:30:49 Guest8466 joins (~Guest84@188.27.129.10)
2021-07-07 07:32:32 chele joins (~chele@user/chele)
2021-07-07 07:32:46 Hatz_ is now known as hatz_
2021-07-07 07:36:49 mpt joins (~tom@2a02:908:1862:49e0::8)
2021-07-07 07:36:57 × ptr_frac7al quits (~longlong@user/ptr-frac7al/x-0038398) (Ping timeout: 252 seconds)
2021-07-07 07:38:56 <tomsmeding> dibblego: foldr replaces constructors, not foldl; but I assume that was a typo :)
2021-07-07 07:39:09 × Nyeogmi quits (~Nyeogmi@2601:645:8700:bea0:4d5e:7bf4:e290:5648) (Ping timeout: 252 seconds)
2021-07-07 07:39:54 <dibblego> I said that rite
2021-07-07 07:40:16 <tomsmeding> your second-to-last message
2021-07-07 07:40:35 <dibblego> "foldl replaces constructors" is a lie
2021-07-07 07:40:36 <tomsmeding> well, your message is strictly speaking correct; "foldl replaces constructors" is a lie, and a big one :p
2021-07-07 07:40:48 <dibblego> yes, that was the discussion

All times are in UTC.