Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,801,952 events total
2025-12-03 13:49:29 <__monty__> Is there a fold/mapAccum where you can shortcircuit the folding and return the tail unaltered?
2025-12-03 13:49:57 <lucabtz> yeah i realized
2025-12-03 13:50:10 <lucabtz> i put NamedFieldPuns on the whole cabal project now
2025-12-03 13:54:03 <lucabtz> actually i cant get it to work in construction
2025-12-03 13:54:35 trickard_ is now known as trickard
2025-12-03 13:56:19 tromp joins (~textual@2001:1c00:3487:1b00:a4ed:9e46:fd5d:6b4e)
2025-12-03 14:01:44 <lucabtz> having colliding names does work as nicely because i need to import the record selectors for the construction to work
2025-12-03 14:02:26 <lucabtz> but when importing the selector it will collide with the other thing named the same
2025-12-03 14:03:40 <Leary> `NoFieldSelectors` might help
2025-12-03 14:04:01 <merijn> NoFieldSelectors is bae
2025-12-03 14:05:06 divlamir_ joins (~divlamir@user/divlamir)
2025-12-03 14:05:18 spew joins (~spew@user/spew)
2025-12-03 14:05:38 × gawen quits (~gawen@user/gawen) (Quit: cya)
2025-12-03 14:06:03 <lucabtz> great
2025-12-03 14:07:09 <lucabtz> i will try
2025-12-03 14:07:12 <lucabtz> thank you again
2025-12-03 14:07:16 × divlamir quits (~divlamir@user/divlamir) (Ping timeout: 256 seconds)
2025-12-03 14:07:17 divlamir_ is now known as divlamir
2025-12-03 14:08:15 × akegalj quits (~akegalj@141-138-27-206.dsl.iskon.hr) (Ping timeout: 240 seconds)
2025-12-03 14:09:58 wbooze joins (~inline@cgn-195-14-221-120.nc.de)
2025-12-03 14:10:22 wbooze is now known as Guest6657
2025-12-03 14:14:18 × leah2 quits (~leah@vuxu.org) (Quit: Sprechen Sie noch? Wird noch gesprochen? Ich trenne.)
2025-12-03 14:15:35 × chromoblob quits (~chromoblo@user/chromob1ot1c) (Read error: Connection reset by peer)
2025-12-03 14:15:53 chromoblob joins (~chromoblo@user/chromob1ot1c)
2025-12-03 14:16:54 <__monty__> `mapAccumL` with a Maybe for the state to indicate when the map should fall back to basically `id` feels wrong.
2025-12-03 14:17:28 × chexum quits (~quassel@gateway/tor-sasl/chexum) (Remote host closed the connection)
2025-12-03 14:17:29 leah2 joins (~leah@vuxu.org)
2025-12-03 14:17:41 chexum joins (~quassel@gateway/tor-sasl/chexum)
2025-12-03 14:21:01 gawen joins (~gawen@user/gawen)
2025-12-03 14:27:59 Guest35 joins (~Guest35@2607:fa49:1940:8200:c958:535b:5462:796d)
2025-12-03 14:28:29 <kuribas`> __monty__: sounds like you want mapAccumR
2025-12-03 14:28:32 <kuribas`> :t mapAccumR
2025-12-03 14:28:35 <lambdabot> Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
2025-12-03 14:29:04 × Guest35 quits (~Guest35@2607:fa49:1940:8200:c958:535b:5462:796d) (Client Quit)
2025-12-03 14:29:16 <kuribas`> err
2025-12-03 14:29:23 <__monty__> I don't think so. Neither direction allows "shortcutting".
2025-12-03 14:29:38 <kuribas`> scanr?
2025-12-03 14:30:04 <kuribas`> scanr over tails...
2025-12-03 14:30:15 <__monty__> I don't see how that relates.
2025-12-03 14:30:28 Guest35 joins (~Guest35@2607:fa49:1940:8200:c958:535b:5462:796d)
2025-12-03 14:30:37 Googulator68 joins (~Googulato@2a01-036d-0106-479c-d9ec-010d-f188-ffcb.pool6.digikabel.hu)
2025-12-03 14:30:44 × Googulator quits (~Googulato@2a01-036d-0106-479c-d9ec-010d-f188-ffcb.pool6.digikabel.hu) (Quit: Client closed)
2025-12-03 14:30:44 × Pozyomka quits (~pyon@user/pyon) (Quit: brb)
2025-12-03 14:31:00 <__monty__> The output is the same structure and length as the input. I'm pushing a value down into a structure, based on a condition I either push another value down or stop pushing any values down.
2025-12-03 14:31:08 × Googulator68 quits (~Googulato@2a01-036d-0106-479c-d9ec-010d-f188-ffcb.pool6.digikabel.hu) (Client Quit)
2025-12-03 14:31:13 Googulator40 joins (~Googulato@2a01-036d-0106-479c-d9ec-010d-f188-ffcb.pool6.digikabel.hu)
2025-12-03 14:31:19 <tomsmeding> do you have a specific reason for wanting this to be a pre-existing combinator?
2025-12-03 14:31:59 <__monty__> Intellectual curiosity mostly. It seems like something that could have an elegant combinator.
2025-12-03 14:32:17 <tomsmeding> I don't think any of the standard L/R combinators apply here -- the L ones because they continue recursing regardless, and the R ones because the information flow is the wrong way
2025-12-03 14:32:43 <tomsmeding> you can implement this with a foldr in a way similar that you can build foldl using foldr
2025-12-03 14:32:56 <tomsmeding> but I don't think it's a pre-existing combinator, at least in base
2025-12-03 14:33:07 × Guest35 quits (~Guest35@2607:fa49:1940:8200:c958:535b:5462:796d) (Write error: Broken pipe)
2025-12-03 14:33:26 <__monty__> Yep, but foldr and mapAccumL both have to process every element of the structure, no? Since I don't want to outright drop the tail.
2025-12-03 14:33:40 <kuribas`> __monty__: not foldr
2025-12-03 14:33:57 <tomsmeding> yeah thinking about this more I'm not sure anymore that you can do this using foldr
2025-12-03 14:34:11 <__monty__> tomsmeding: You can implement mapAccumL using foldr.
2025-12-03 14:34:15 <tomsmeding> I know
2025-12-03 14:34:29 <tomsmeding> base's foldl is implemented using foldr
2025-12-03 14:34:46 <tomsmeding> but while that construction is cute, I don't think you get access to the unadulterated tail
2025-12-03 14:35:01 <__monty__> kuribas`: Show me a foldr that doesn't drop any values and also doesn't visit a tail of several values.
2025-12-03 14:35:58 <__monty__> Yeah, with foldr you can either process every element, or drop whatever's left.
2025-12-03 14:36:23 <tomsmeding> yes I think so
2025-12-03 14:37:20 <sprout> you can do a scan instead of a fold and lazily stop evaluating when you hit something
2025-12-03 14:37:26 <__monty__> But that's not the "shortcutting" I'm looking for. I want to recurse up to a point and at that point return the tail unprocessed. The latter is just for efficiency rather than correctness.
2025-12-03 14:37:48 <tomsmeding> sprout: scan doesn't give you access to the actual original tail
2025-12-03 14:37:53 <__monty__> sprout: Again, that leaves me with only part of the input, no?
2025-12-03 14:37:55 akegalj joins (~akegalj@141-138-27-206.dsl.iskon.hr)
2025-12-03 14:37:57 <sprout> hmyah
2025-12-03 14:37:58 Pozyomka joins (~pyon@user/pyon)
2025-12-03 14:39:45 <sprout> put it in a monad? I feel like parser combinators will often return the unprocessed tokens on an error, so you should be able to reuse the idiom
2025-12-03 14:40:24 <tomsmeding> then you just punt the problem to the implementation of that monad
2025-12-03 14:40:33 <sprout> yah
2025-12-03 14:45:27 × gawen quits (~gawen@user/gawen) (Quit: cya)
2025-12-03 14:47:39 × Guest6657 quits (~inline@cgn-195-14-221-120.nc.de) (Quit: Leaving)
2025-12-03 14:51:23 wbooze joins (~inline@cgn-195-14-221-120.nc.de)
2025-12-03 14:59:30 <kuribas`> > foldr (\(x:xs) cont -> \xs2 -> if (x > 5) then (x:xs) else (x*2) : cont xs) id (tails [1..10]) []
2025-12-03 14:59:36 <lambdabot> [2,4,6,8,10,6,7,8,9,10]
2025-12-03 14:59:41 <kuribas`> ^ __monty__
2025-12-03 15:00:00 <kuribas`> obviously needs some lambdacase.
2025-12-03 15:00:45 × spew quits (~spew@user/spew) (Ping timeout: 245 seconds)
2025-12-03 15:01:28 × divlamir quits (~divlamir@user/divlamir) (Ping timeout: 244 seconds)
2025-12-03 15:01:59 × ttybitnik quits (~ttybitnik@user/wolper) (Quit: Fading out...)
2025-12-03 15:02:40 × lucabtz quits (~lucabtz@user/lucabtz) (Remote host closed the connection)
2025-12-03 15:03:03 spew joins (~spew@user/spew)
2025-12-03 15:04:23 <kuribas`> > take 10 $ foldr (\(x:xs) cont -> \xs2 -> if (x > 5) then (x:xs) else (x*2) : cont xs) id (tails [1..]) []
2025-12-03 15:04:26 <lambdabot> [2,4,6,8,10,6,7,8,9,10]
2025-12-03 15:04:39 <kuribas`> --proof that it doesn't visit the tail :)
2025-12-03 15:04:45 amadaluzia joins (~amadaluzi@user/amadaluzia)
2025-12-03 15:05:29 lucabtz joins (~lucabtz@user/lucabtz)
2025-12-03 15:05:52 <__monty__> Only shortcoming is if the condition is never fulfilled, needs more case analysis.
2025-12-03 15:07:06 <__monty__> Feels a lot like span/break and folding the fst.
2025-12-03 15:07:41 <__monty__> Hmm, no the span/break would need to carry state forward.
2025-12-03 15:08:38 <kuribas`> Actually, this doesn't use the continuation ...
2025-12-03 15:08:41 <kuribas`> > foldr (\(x:xs) xs2 -> if (x > 5) then (x:xs) else (x*2) : xs2) [] (tails [1..10])
2025-12-03 15:08:44 <lambdabot> [2,4,6,8,10,6,7,8,9,10]
2025-12-03 15:09:08 <kuribas`> You can use the continuation if you need to pass some state.
2025-12-03 15:09:40 × wbooze quits (~inline@cgn-195-14-221-120.nc.de) (Quit: Leaving)
2025-12-03 15:10:08 gawen joins (~gawen@user/gawen)
2025-12-03 15:10:27 <__monty__> > foldr (\(x:xs) xs2 -> if False then (x:xs) else (x*2) : xs2) [] (tails [1..10])
2025-12-03 15:10:30 <lambdabot> [2,4,6,8,10,12,14,16,18,20*Exception: <interactive>:3:8-59: Non-exhaustive p...

All times are in UTC.