Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,804,069 events total
2025-09-10 11:17:08 <kqr> Backing up further, I want to compare the performance of using the RandT transformer layered on top of IO to drawing numbers in IO directly.
2025-09-10 11:18:45 × chromoblob quits (~chromoblo@user/chromob1ot1c) (Ping timeout: 258 seconds)
2025-09-10 11:19:48 <kqr> Thus I'd like to create a `shuffle :: MonadRandom m => [a] -> m [a]` to be used both from within a RandT stack and directly from IO. However, with the given tools I can only create `shuffle :: RandomGen g => [a] -> Rand g [a]` which can only be used in IO by running it with evalRandIO which goes through StateT in the end.
2025-09-10 11:19:56 xff0x joins (~xff0x@2405:6580:b080:900:c68c:683e:9c65:6f0a)
2025-09-10 11:23:16 <dminuoso> kqr: Like I said, `MonadRandom IO` exists
2025-09-10 11:23:47 <dminuoso> So you can use `shuffle` in IO just the same as you would with RandT.
2025-09-10 11:25:45 <kqr> Well, I certainly am missing something dumb here. The function I import is `List.Shuffle.shuffle :: RandomGen g => [a] -> g -> ([a], g)`. How would I turn that into `shuffle' :: MonadRandom m => [a] -> m [a]`?
2025-09-10 11:26:12 × gmg quits (~user@user/gehmehgeh) (Quit: Leaving)
2025-09-10 11:27:24 <dminuoso> kqr: These are different interfaces.
2025-09-10 11:28:41 <kqr> Yes, and I wished to convert one into the other, but I'm starting to sense that it might not be possible, and the solution would have be `shuffle' :: (RandomGen g, MonadSplit g m) => [a] -> m [a]`
2025-09-10 11:28:59 <dminuoso> Well Im not entirely sure what you mean by converting RandomGen into MonadRandom.
2025-09-10 11:29:17 × Lord_of_Life quits (~Lord@user/lord-of-life/x-2819915) (Ping timeout: 250 seconds)
2025-09-10 11:29:28 <dminuoso> RandomGen is for sequential pseudorandom number generators.
2025-09-10 11:29:45 × ss4 quits (~wootehfoo@user/wootehfoot) (Quit: Leaving)
2025-09-10 11:32:23 <kqr> I feel like anything that is an instance of MonadRandom ought to be able to take a function of the shape `RandomGen g => g -> (a, g)` and produce an a, i.e. there ought to be a function in `MonadRandom m` that is `liftRandom :: RandomGen g => (g -> (a, g)) -> m a`.
2025-09-10 11:34:05 chromoblob joins (~chromoblo@user/chromob1ot1c)
2025-09-10 11:39:20 <kqr> But I think my misunderstanding is in believing instances of MonadRandom have to be able to expose their generator. Turns out they do not. And there's no typeclass for those instances that do, beyond MonadSplit which is even more restricted.
2025-09-10 11:43:29 <dminuoso> kqr: They are kind of orthotonal interfaces.
2025-09-10 11:46:46 <dminuoso> kqr: And more to the point, MonadRandom IO is not even implemented using RandomGen.
2025-09-10 11:47:02 <dminuoso> It uses `randomIO` from the `random` package (I dont even know why)
2025-09-10 11:47:25 <dminuoso> Which ultimately uses `https://hackage-content.haskell.org/package/random-1.3.1/docs/src/System.Random.Internal.html#theStdGen`
2025-09-10 11:48:34 <dminuoso> And since theStdGen is exported in that module, you can - if you want - access that for purpose of testing.
2025-09-10 11:49:25 <dminuoso> Oh wait, I missed a key detail. That is a plain RandomGEn
2025-09-10 11:50:02 <dminuoso> kqr: So you could think of `MonadRandom` as a kind of `State StdGen` maybe.
2025-09-10 11:51:04 × merijn quits (~merijn@77.242.116.146) (Read error: Connection reset by peer)
2025-09-10 11:51:47 × tv quits (~tv@user/tv) (Read error: Connection reset by peer)
2025-09-10 11:52:26 merijn joins (~merijn@77.242.116.146)
2025-09-10 11:57:44 × merijn quits (~merijn@77.242.116.146) (Ping timeout: 248 seconds)
2025-09-10 11:59:36 merijn joins (~merijn@77.242.116.146)
2025-09-10 12:02:08 × chromoblob quits (~chromoblo@user/chromob1ot1c) (Read error: Connection reset by peer)
2025-09-10 12:02:27 chromoblob joins (~chromoblo@user/chromob1ot1c)
2025-09-10 12:02:47 × weary-traveler quits (~user@user/user363627) (Remote host closed the connection)
2025-09-10 12:03:54 <kqr> That's my intuition too, but since MonadRandom does not expose any way to get the StdGen, a function like shuffle cannot be lifted into a MonadRandom operation.
2025-09-10 12:04:18 Lord_of_Life joins (~Lord@user/lord-of-life/x-2819915)
2025-09-10 12:07:03 tv joins (~tv@user/tv)
2025-09-10 12:07:15 × trickard_ quits (~trickard@cpe-54-98-47-163.wireline.com.au) (Read error: Connection reset by peer)
2025-09-10 12:09:02 gmg joins (~user@user/gehmehgeh)
2025-09-10 12:09:41 × fp quits (~Thunderbi@wireless-86-50-141-202.open.aalto.fi) (Quit: fp)
2025-09-10 12:09:45 fp1 joins (~Thunderbi@wireless-86-50-141-202.open.aalto.fi)
2025-09-10 12:10:02 trickard_ joins (~trickard@cpe-54-98-47-163.wireline.com.au)
2025-09-10 12:10:19 × raym quits (~ray@user/raym) (Ping timeout: 260 seconds)
2025-09-10 12:11:36 × merijn quits (~merijn@77.242.116.146) (Ping timeout: 248 seconds)
2025-09-10 12:12:03 fp1 is now known as fp
2025-09-10 12:14:54 merijn joins (~merijn@77.242.116.146)
2025-09-10 12:15:52 × segfaultfizzbuzz quits (~segfaultf@23-93-74-222.fiber.dynamic.sonic.net) (Ping timeout: 258 seconds)
2025-09-10 12:24:46 segfaultfizzbuzz joins (~segfaultf@23-93-74-222.fiber.dynamic.sonic.net)
2025-09-10 12:32:07 × chromoblob quits (~chromoblo@user/chromob1ot1c) (Ping timeout: 250 seconds)
2025-09-10 12:33:56 × fp quits (~Thunderbi@wireless-86-50-141-202.open.aalto.fi) (Quit: fp)
2025-09-10 12:34:04 fp1 joins (~Thunderbi@wireless-86-50-141-202.open.aalto.fi)
2025-09-10 12:36:22 fp1 is now known as fp
2025-09-10 12:49:07 chromoblob joins (~chromoblo@user/chromob1ot1c)
2025-09-10 13:06:41 ttybitnik joins (~ttybitnik@user/wolper)
2025-09-10 13:14:57 <kqr> Unrelated to the above: I have a list of things where I want to occasionally perform the query listWithout :: Eq a => [a] -> a -> Maybe [a] which is Nothing if the element does not exist in the list, or Just xs-wihtout-element if the element did exist. This is obviously a Set, except the list can and is allowed to contain duplicates (and in that case only one of the element should be removed).
2025-09-10 13:15:00 <kqr> What would be the most efficient way to store this list? Asking because profiling indicates that "list-except-element" query is where my program spends nearly 20 % of its time. I have already optimised it to be tail-recursive and perform a single iteration through the list, but it's still slow.
2025-09-10 13:15:15 itaipu joins (~itaipu@168.121.97.28)
2025-09-10 13:16:23 <kqr> I imagine a Map element Int would do it, where the Int records the number of instances of the element, but I'm also worried that might be a lot of overhead compared to a list. (In this case, the list is usually fairly short (< 10 items) and probably rarely contains more than three duplicates.)
2025-09-10 13:17:02 × dfg quits (~dfg@user/dfg) (Ping timeout: 260 seconds)
2025-09-10 13:17:34 × Enrico63 quits (~Enrico63@2a0b:e541:10d0:0:9efc:e8ff:fe24:3213) (Quit: Client closed)
2025-09-10 13:18:34 humasect joins (~humasect@dyn-192-249-132-90.nexicom.net)
2025-09-10 13:23:20 dfg joins (~dfg@dfg.rocks)
2025-09-10 13:23:20 × dfg quits (~dfg@dfg.rocks) (Changing host)
2025-09-10 13:23:20 dfg joins (~dfg@user/dfg)
2025-09-10 13:23:48 califax_ joins (~califax@user/califx)
2025-09-10 13:24:12 × califax quits (~califax@user/califx) (Ping timeout: 272 seconds)
2025-09-10 13:25:05 califax_ is now known as califax
2025-09-10 13:26:25 <haskellbridge> <sm> kqr I thought of a Map also. I think it's worth a try, often Map has been used in optimisations
2025-09-10 13:26:44 × segfaultfizzbuzz quits (~segfaultf@23-93-74-222.fiber.dynamic.sonic.net) (Ping timeout: 260 seconds)
2025-09-10 13:27:00 <haskellbridge> <sm> some kind of map
2025-09-10 13:27:47 × itaipu quits (~itaipu@168.121.97.28) (Ping timeout: 256 seconds)
2025-09-10 13:31:50 <kqr> I'll give it a shot. Going to take some refactoring but I'd probably need to do that at some point anyway.
2025-09-10 13:37:35 Enrico63 joins (~Enrico63@2a0b:e541:10d0:0:9efc:e8ff:fe24:3213)
2025-09-10 13:41:04 itaipu joins (~itaipu@168.121.97.28)
2025-09-10 13:41:18 × Enrico63 quits (~Enrico63@2a0b:e541:10d0:0:9efc:e8ff:fe24:3213) (Client Quit)
2025-09-10 13:42:08 segfaultfizzbuzz joins (~segfaultf@23-93-74-222.fiber.dynamic.sonic.net)
2025-09-10 13:48:20 BLade_X123 joins (~manju@user/BLade-X123:75192)
2025-09-10 13:48:38 × segfaultfizzbuzz quits (~segfaultf@23-93-74-222.fiber.dynamic.sonic.net) (Ping timeout: 258 seconds)
2025-09-10 13:49:37 × fp quits (~Thunderbi@wireless-86-50-141-202.open.aalto.fi) (Ping timeout: 248 seconds)
2025-09-10 13:50:21 fp joins (~Thunderbi@wireless-86-50-141-202.open.aalto.fi)
2025-09-10 13:51:20 × BLade_X123 quits (~manju@user/BLade-X123:75192) (Quit: Leaving)
2025-09-10 13:51:57 × ttybitnik quits (~ttybitnik@user/wolper) (Quit: Fading out...)
2025-09-10 13:55:28 segfaultfizzbuzz joins (~segfaultf@23-93-74-222.fiber.dynamic.sonic.net)
2025-09-10 13:58:03 × chromoblob quits (~chromoblo@user/chromob1ot1c) (Read error: Connection reset by peer)
2025-09-10 13:58:20 chromoblob joins (~chromoblo@user/chromob1ot1c)
2025-09-10 13:58:37 × humasect quits (~humasect@dyn-192-249-132-90.nexicom.net) (Quit: Leaving...)
2025-09-10 13:58:41 × jespada quits (~jespada@r179-25-67-56.dialup.adsl.anteldata.net.uy) (Ping timeout: 248 seconds)
2025-09-10 14:01:47 jespada joins (~jespada@r190-135-93-147.dialup.adsl.anteldata.net.uy)
2025-09-10 14:02:07 × mange quits (~mange@user/mange) (Quit: Zzz...)
2025-09-10 14:20:37 gorignak joins (~gorignak@user/gorignak)
2025-09-10 14:23:40 Tuplanolla joins (~Tuplanoll@91-159-69-59.elisa-laajakaista.fi)
2025-09-10 14:24:17 × pavonia quits (~user@user/siracusa) (Quit: Bye!)
2025-09-10 14:29:09 × TMA quits (tma@twin.jikos.cz) (Ping timeout: 260 seconds)
2025-09-10 14:31:00 TMA joins (tma@twin.jikos.cz)
2025-09-10 14:42:55 <merijn> kqr: How static are these lists?
2025-09-10 14:43:49 <EvanR> how large are these lists
2025-09-10 14:44:12 <EvanR> 10 items at most, yeah Map representing the histogram will have overhead
2025-09-10 14:44:26 <merijn> I was more thinking: If you
2025-09-10 14:44:42 <merijn> If you're spending so much time on them, do you not wanna switch to Vector or something
2025-09-10 14:44:58 <merijn> You're gonna waste a lot of time pointer changing with a list
2025-09-10 14:45:04 <merijn> *chasing
2025-09-10 14:45:37 <EvanR> what's the distribution of importance placed on all the tasks the data structure does, assuming it does something else but track the population

All times are in UTC.