Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→
Page 1 .. 428 429 430 431 432 433 434 435 436 437 438 .. 17998
1,799,724 events total
2021-06-13 08:30:00 <tomsmeding> data Some f where Some :: f a -> Some f -- or alternatively, same meaning different syntax: data Some f = forall a. Some (f a)
2021-06-13 08:30:04 <tomsmeding> or use:
2021-06-13 08:30:05 <tomsmeding> @hackage some
2021-06-13 08:30:05 <lambdabot> https://hackage.haskell.org/package/some
2021-06-13 08:31:03 __monty__ joins (~toonn@user/toonn)
2021-06-13 08:31:33 <tomsmeding> which makes Some a newtype using some unsafeCoerce magic
2021-06-13 08:32:46 <tomsmeding> siers: to answer your original question, I guess: for most people that's making two datatypes, data A = A and data B = B, and having a function splitD :: [D] -> ([A], [B])
2021-06-13 08:32:58 <jasonm> can Some be used to have a list of types that implement some typeclass?
2021-06-13 08:32:59 <tomsmeding> and for the people that like type-level trickery, the GADT solution that I described
2021-06-13 08:33:07 Rembane_ is now known as Rembane
2021-06-13 08:33:21 <tomsmeding> jasonm: do you have an example?
2021-06-13 08:33:47 <siers> "mkSome" :D funny... is Some like a Proxy? I don't yet understand what it does
2021-06-13 08:34:05 × MQ-17J quits (~MQ-17J@8.21.10.116) (Ping timeout: 245 seconds)
2021-06-13 08:34:06 <tomsmeding> siers: 'Some Maybe' is a type that contains a 'Maybe a' for some existential 'a'
2021-06-13 08:34:07 <jasonm> tomsmeding, having a list of Show a => [a], for example. existential types can be used for this
2021-06-13 08:34:40 <tomsmeding> siers: in this case, with my GADT-based D, you can have a list of 'Some D' where each item is a 'D a' for some existential 'a' -- i.e. either 'True or 'False in this case
2021-06-13 08:34:45 × matsurago quits (~matsurago@nttkyo1618187.tkyo.nt.ngn.ppp.infoweb.ne.jp) (Quit: Leaving)
2021-06-13 08:35:06 <siers> tomsmeding, it's starting to make sense
2021-06-13 08:35:15 <siers> the some part // the D a part is clear
2021-06-13 08:35:23 hmmmas joins (~chenqisu1@183.217.200.246)
2021-06-13 08:35:31 <tomsmeding> it's not like a Proxy in that a Proxy has only a phantom type variable; Some carries data but hides one type variable behind an existential
2021-06-13 08:37:09 <tomsmeding> but you don't have to use Some for your D; you can also directly write: data SomeD where SomeD :: D a -> SomeD -- or equivalently: data SomeD = forall a. SomeD (D a)
2021-06-13 08:37:14 <siers> but if TagInt :: Tag Int, then shouldn't Some TagInt be Some Tag?
2021-06-13 08:37:16 × fizbin quits (~fizbin@2601:8a:4080:1280:d58e:2782:3061:3fa3) (Remote host closed the connection)
2021-06-13 08:37:30 <tomsmeding> siers: is TagInt a constructor of a GADT named Tag?
2021-06-13 08:37:39 <maerwald> tomsmeding: your example requires using a different type... I was thinking of type families
2021-06-13 08:37:44 <tomsmeding> then yes Some TagInt :: Some Tag
2021-06-13 08:37:45 <siers> tomsmeding, ah, gotcha
2021-06-13 08:38:06 <siers> I'm not used to data .. where syntax
2021-06-13 08:38:40 <tomsmeding> jasonm: (sorry missed your message) no for that you have to write a custom GADT
2021-06-13 08:39:06 <jasonm> ok
2021-06-13 08:39:39 <tomsmeding> or, I guess, Some (Product (Has Show) []), where Product is from Data.Functor.Product, and data Has c a where Has :: c a => Has c a
2021-06-13 08:39:54 <tomsmeding> (using ConstraintKinds to pass a constraint to the type variable 'c' of Has)
2021-06-13 08:40:06 <tomsmeding> but at that point just write a custom GADT :p
2021-06-13 08:40:11 yoctocell joins (~yoctocell@h87-96-130-155.cust.a3fiber.se)
2021-06-13 08:40:45 <tomsmeding> siers: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/gadt.html?highlight=gadts
2021-06-13 08:40:51 <tomsmeding> maerwald: I'm not sure I see how?
2021-06-13 08:42:59 × eggplantade quits (~Eggplanta@2600:1700:bef1:5e10:4587:6292:4bfd:4d24) (Remote host closed the connection)
2021-06-13 08:43:04 <siers> tomsmeding, cool link
2021-06-13 08:43:17 <tomsmeding> siers: the ghc user's guide is underappreciated
2021-06-13 08:43:35 eggplantade joins (~Eggplanta@2600:1700:bef1:5e10:4587:6292:4bfd:4d24)
2021-06-13 08:44:42 Ariakenom joins (~Ariakenom@2001:9b1:efb:fc00:b19b:35e2:2fd0:444d)
2021-06-13 08:44:46 × tomsmeding quits (~tomsmedin@tomsmeding.com) (Quit: ZNC 1.8.2 - https://znc.in)
2021-06-13 08:46:06 tomsmeding joins (~tomsmedin@tomsmeding.com)
2021-06-13 08:48:09 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 252 seconds)
2021-06-13 08:48:09 × jneira quits (~jneira@166.red-81-39-172.dynamicip.rima-tde.net) (Ping timeout: 252 seconds)
2021-06-13 08:48:28 × eggplantade quits (~Eggplanta@2600:1700:bef1:5e10:4587:6292:4bfd:4d24) (Ping timeout: 268 seconds)
2021-06-13 08:49:31 × dunkeln quits (~dunkeln@94.129.65.28) (Ping timeout: 245 seconds)
2021-06-13 08:50:34 wallymathieu joins (~wallymath@81-234-151-21-no94.tbcn.telia.com)
2021-06-13 08:53:14 × lavaman quits (~lavaman@98.38.249.169) (Remote host closed the connection)
2021-06-13 08:54:58 fendor_ joins (~fendor@77.119.131.227.wireless.dyn.drei.com)
2021-06-13 08:57:57 × fendor quits (~fendor@91.141.0.106.wireless.dyn.drei.com) (Ping timeout: 264 seconds)
2021-06-13 09:00:07 berberman joins (~berberman@user/berberman)
2021-06-13 09:00:42 <maerwald> tomsmeding: yeah, on second thought... me neither
2021-06-13 09:01:02 <tomsmeding> :)
2021-06-13 09:01:30 × berberman_ quits (~berberman@user/berberman) (Ping timeout: 264 seconds)
2021-06-13 09:02:43 neceve joins (~quassel@2a02:c7f:607e:d600:a95a:ecd2:e57a:3130)
2021-06-13 09:03:06 dunkeln joins (~dunkeln@94.129.65.28)
2021-06-13 09:06:54 × xff0x quits (~xff0x@2001:1a81:53db:9400:2ec8:4cb:1537:c74) (Ping timeout: 264 seconds)
2021-06-13 09:07:50 Tuplanolla joins (~Tuplanoll@91-159-68-239.elisa-laajakaista.fi)
2021-06-13 09:08:22 xff0x joins (~xff0x@2001:1a81:53dc:de00:96fb:36f9:fddc:a0cb)
2021-06-13 09:08:26 hseg joins (~gesh@185.120.126.41)
2021-06-13 09:10:28 da39a3ee5e6b4b0d joins (~textual@2403:6200:8876:2955:1da4:ecb3:1c84:7a5a)
2021-06-13 09:11:07 × hnOsmium0001 quits (uid453710@id-453710.stonehaven.irccloud.com) (Quit: Connection closed for inactivity)
2021-06-13 09:14:00 <hseg> Hi. I want a function :: Semigroup v => (k -> v -> [l]) -> Map k v -> Map l v that replaces all (k,v) pairs in the map by their image, then collects them all, sconcat'ing if there are duplicate keys
2021-06-13 09:14:13 <hseg> The current way I have of doing this is fromListWith (<>) . toList . traverseWithKey f
2021-06-13 09:14:50 <hseg> but a) am unsure whether this will fuse away the intermediate list and b) seems like an awkward way of doing things
2021-06-13 09:14:56 <hseg> am I missing something?
2021-06-13 09:15:21 × Erutuon quits (~Erutuon@user/erutuon) (Ping timeout: 272 seconds)
2021-06-13 09:15:46 <hseg> (in fact, this is the unary case of what is actually a parametrized binary op on Maps in my use case)
2021-06-13 09:16:31 <hseg> (ie convolveF :: (_, Foldable f, Semigroup v) => (i -> j -> f k) -> Map i v -> Map j v -> Map k v
2021-06-13 09:16:59 _ht joins (~quassel@82-169-194-8.biz.kpn.net)
2021-06-13 09:18:25 <tomsmeding> hseg: that function doesn't seem to typecheck
2021-06-13 09:18:48 <hseg> bc of the hole in the context?
2021-06-13 09:19:05 × dunkeln quits (~dunkeln@94.129.65.28) (Ping timeout: 245 seconds)
2021-06-13 09:19:06 <c_wraith> because traverseWithKey is returning a list of maps
2021-06-13 09:19:43 <hseg> ah oops
2021-06-13 09:20:52 <hseg> yeah, ig that intermediate toList should be map toList ?
2021-06-13 09:21:51 <hseg> ... foldMap toList
2021-06-13 09:21:54 <c_wraith> maybe concatMap?
2021-06-13 09:22:01 <hseg> concatMap, right
2021-06-13 09:22:15 <hseg> (though for lists those coincide, right?
2021-06-13 09:22:24 <c_wraith> yeah, those two are the same in that case
2021-06-13 09:23:24 <c_wraith> in that case, I can basically guarantee the intermediate lists are not getting fused away
2021-06-13 09:23:30 <hseg> hrm... a moment, I made a mistake in my type tetris
2021-06-13 09:23:33 × tzh_ quits (~tzh@c-24-21-73-154.hsd1.or.comcast.net) (Quit: zzz)
2021-06-13 09:23:45 <hseg> (the traversal is modifying the values, not the keys)
2021-06-13 09:23:58 <hseg> but the general point is clear
2021-06-13 09:24:31 <hseg> ig that containers doesn't provide a clean, quick way of doing this then?
2021-06-13 09:24:55 <hseg> and that i need to use monoidal-containers instead?
2021-06-13 09:24:57 <c_wraith> Not clean, but foldlWithKey' would be efficient.
2021-06-13 09:25:22 <c_wraith> though it doesn't do a thing for your binary case
2021-06-13 09:25:48 <hseg> oh well. it's what I get for abusing a container outside its intended use case
2021-06-13 09:26:25 <hseg> Map k v is meant to be "v-valued container keyed by k", not "v-valuation on k values"
2021-06-13 09:28:14 mc47 joins (~mc47@xmonad/TheMC47)
2021-06-13 09:28:25 × teaSlurper quits (~chris@81.96.113.213) (Remote host closed the connection)
2021-06-13 09:29:19 <hseg> ... actually, instead of destructing+reconstructing, could just unionsWith (<>)
2021-06-13 09:29:28 <hseg> so at least there's that
2021-06-13 09:29:56 <tomsmeding> which is, then, probably the best you'll get
2021-06-13 09:30:06 <hseg> ... and that's yet another thing Map has that HashMap doesn't *frustration*

All times are in UTC.