Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-03-12 21:53:44 <blueonyx> hi, i'm learning lenses to use with aeson. so i was wondering if there is a more consise/pointfree version for f in https://friendpaste.com/1JmADDcGOj7hEn7CtCwbXl?
2021-03-12 21:53:46 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed)
2021-03-12 21:54:00 <sm[m]> wz1000: dang, that's work for computers
2021-03-12 21:54:05 royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-03-12 21:55:07 <dmj`> wz1000: ah yea, because GHC only optimizes on a per module basis
2021-03-12 21:55:11 <wz1000> sm[m]: how so? It compiles, and it seems to work
2021-03-12 21:55:16 <dmj`> wz1000: that's cool, will try
2021-03-12 21:55:33 <wz1000> sm[m]: I can't think of a computer smart enough to solve it
2021-03-12 21:55:49 <sm[m]> wz1000: really, then I'll have to study it more
2021-03-12 21:56:24 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Max SendQ exceeded)
2021-03-12 21:56:43 royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-03-12 21:57:08 × monadmatt quits (~user@119-17-128-101.771180.mel.nbn.aussiebb.net) (Ping timeout: 245 seconds)
2021-03-12 21:58:06 <wz1000> sm[m]: the intent of the code was to check if every element in a list satisfies a condition, and if so return a Just <number of 1s in the list>, else return Nothing
2021-03-12 21:58:23 <wz1000> the problem was to figure out why this is not optimal
2021-03-12 21:58:34 × zebrag quits (~inkbottle@aaubervilliers-654-1-101-29.w86-212.abo.wanadoo.fr) (Quit: Konversation terminated!)
2021-03-12 21:58:37 usr25 joins (~usr25@unaffiliated/usr25)
2021-03-12 21:58:56 zebrag joins (~inkbottle@aaubervilliers-654-1-101-29.w86-212.abo.wanadoo.fr)
2021-03-12 21:58:58 × stree quits (~stree@68.36.8.116) (Ping timeout: 276 seconds)
2021-03-12 22:00:24 <Gurkenglas> > (let f ~(Just x) = Just () in fix f, let g (Just x) = Just () in fix g) -- neat
2021-03-12 22:00:27 <lambdabot> (Just (),*Exception: <<loop>>
2021-03-12 22:00:48 <infinisil> Is there something like `class RecLimitShow a where recLimitShow :: Int -> a -> String` with a default for `Generic a`, which works like `show`, but it only recurses into the structure as deep as the given Int?
2021-03-12 22:01:24 <dolio> f = const (Just ())
2021-03-12 22:01:28 × Varis quits (~Tadas@unaffiliated/varis) (Remote host closed the connection)
2021-03-12 22:01:32 × rj quits (~x@gateway/tor-sasl/rj) (Ping timeout: 268 seconds)
2021-03-12 22:01:39 <infinisil> This could e.g. then print an infinite list to a limited depth
2021-03-12 22:01:52 <Gurkenglas> hmm youre right maybe ill come up with a better example
2021-03-12 22:02:29 <sparsity> infinisil: Foldable?
2021-03-12 22:03:04 <sparsity> recLimitShow :: Foldable f => Int -> f a -> String
2021-03-12 22:03:06 <infinisil> This should also work for e.g. records and sum types
2021-03-12 22:03:17 <sparsity> erg
2021-03-12 22:03:49 <sparsity> well, i would just define your "generic" structure as basically a tree, and then deconstruct those
2021-03-12 22:04:40 <infinisil> That's basically what Generics allow you to do, and I think I could implement this
2021-03-12 22:04:45 <sparsity> https://gist.github.com/fog-hs/19abbf2ee8cf1f9f0c39abf0772da34e
2021-03-12 22:04:48 <infinisil> But I don't want to implement it if it already exists :)
2021-03-12 22:04:51 <sparsity> thats an implementation of it
2021-03-12 22:05:03 rj joins (~x@gateway/tor-sasl/rj)
2021-03-12 22:05:21 <sparsity> it doesnt have the Traversable that your after though. yet, i suppose...
2021-03-12 22:05:36 <Gurkenglas> > both . _Just %~ take 3 $ (let f ~(Just x) = Just $ ():x in fix f, let g (Just x) = Just (():x) in fix g)
2021-03-12 22:05:38 <lambdabot> (Just [(),(),()],*Exception: <<loop>>
2021-03-12 22:05:47 <infinisil> sparsity: That doesn't really look like what I'm after at all?
2021-03-12 22:06:00 <infinisil> Maybe I just don't get it
2021-03-12 22:06:06 <sparsity> well its an implementation of Datatype using Lists and Sums...
2021-03-12 22:06:23 <sparsity> so you should be able to traverse over it like you want
2021-03-12 22:06:32 <sparsity> i just havent written that
2021-03-12 22:06:33 alx741 joins (~alx741@181.196.69.27)
2021-03-12 22:07:06 <sparsity> not sure about translating to it from Generics either...
2021-03-12 22:07:39 <sparsity> its nice that its extensible though
2021-03-12 22:08:09 <infinisil> Well, I'm looking for something that works with Generics, and that has the recursive thing implemented
2021-03-12 22:08:18 <Gurkenglas> or "f ~(Just x) = Just x", thats less baggage around the neat thing, though it would have ended the print early
2021-03-12 22:08:19 <infinisil> So I guess that's not really it :P
2021-03-12 22:08:42 <infinisil> sparsity: Going through a different Tree type also seems like an unnecessary indirection
2021-03-12 22:09:00 <sparsity> i think there is probably a complete implementation of it in the Vinyl package
2021-03-12 22:09:20 <sparsity> sum of products done right...
2021-03-12 22:09:38 × CrazyPython quits (~crazypyth@98.122.164.118) (Remote host closed the connection)
2021-03-12 22:09:38 × dbmikus quits (~dbmikus@cpe-76-167-86-219.natsow.res.rr.com) (Ping timeout: 245 seconds)
2021-03-12 22:09:39 × nbloomf quits (~nbloomf@76.217.43.73) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2021-03-12 22:10:00 <sparsity> oh, the tree thing is totally fundamental to its traversability to some depth - everything is isomorphic to these Sum Product trees
2021-03-12 22:10:18 CrazyPython joins (~crazypyth@98.122.164.118)
2021-03-12 22:10:20 <sparsity> thats the whole point of generics
2021-03-12 22:10:57 <sparsity> but you can write it as an actual datatype as above, instead of using generics you just use that instead of datatypes
2021-03-12 22:11:36 stree joins (~stree@68.36.8.116)
2021-03-12 22:11:36 <infinisil> That sounds way more complicated than I think it has to be..
2021-03-12 22:11:43 <monochrom> dmj`: I'm late to the party. I think that "sum xs / length xs" has a type error, probably two type errors actually. Then again after fixing the type errors, everything you and other said is true too.
2021-03-12 22:12:15 <infinisil> sparsity: I have like 100 data types from third-party libraries I want to use with this, I can't just switch them all to extensible records just to make this work
2021-03-12 22:12:20 <sparsity> well its not really, you would have to basically use generics to translate it into that kind of structure for traversing over anyway
2021-03-12 22:12:37 <sparsity> infinisil: ah, ok
2021-03-12 22:12:50 <monochrom> I do use this to explain to my students fromIntegral and realToFrac.
2021-03-12 22:13:14 <infinisil> sparsity: I don't think so, I think a Generic implementation of this could just recurse with a function call to show the subfields
2021-03-12 22:13:51 <infinisil> Essentially deriving Show, but with an integer that gets passed down and decreased at every level, resulting it "..." if it's 0 without further recursion
2021-03-12 22:14:08 × Techcable quits (~Techcable@168.235.93.147) (Quit: ZNC - https://znc.in)
2021-03-12 22:14:44 × CrazyPython quits (~crazypyth@98.122.164.118) (Ping timeout: 256 seconds)
2021-03-12 22:15:02 × ericsagnes quits (~ericsagne@2405:6580:0:5100:ff67:b2c7:65c7:54f0) (Ping timeout: 264 seconds)
2021-03-12 22:15:22 <sparsity> all of these nestings are isomorphic to trees, its just a big datatype'esque tree thing, and thats what the code above does, the only problem is translating to it and using it, i think if you just want a library you can use, it might be worth looking at Vinyl
2021-03-12 22:15:59 <infinisil> Yeah no I don't think that's what I want
2021-03-12 22:16:10 <dmj`> monochrom: yes, the (/) :: Fractional a => a -> a -> a doesn't mix well with the `Int` returned by `sum`, necessitating `fromIntegral`. I'd view the lack of a type signature altogether as another problem to be pointed out.
2021-03-12 22:16:23 <sparsity> surely lenses must have generic traversals
2021-03-12 22:16:31 × conal_ quits (~conal@64.71.133.70) (Ping timeout: 276 seconds)
2021-03-12 22:16:31 <dmj`> monochrom: it's a good juicy question, seemingly innocuous code heap exhausts
2021-03-12 22:17:01 Techcable joins (~Techcable@168.235.93.147)
2021-03-12 22:17:08 × cole-h quits (~cole-h@c-73-48-197-220.hsd1.ca.comcast.net) (Ping timeout: 245 seconds)
2021-03-12 22:17:09 justan0theruser is now known as justanotheruser
2021-03-12 22:17:51 <sparsity> im not sure you can do it *without* translating to an extensible datatype.... unless Generics gives this traversable directly, which im not sure it does
2021-03-12 22:17:53 ericsagnes joins (~ericsagne@2405:6580:0:5100:1715:de72:a1c7:dcd1)
2021-03-12 22:18:59 <sparsity> vinyl should probably have a way to spin something up from a derived Generic
2021-03-12 22:19:14 × spoonm quits (~spoonm@tokyo.spoonm.org) (Ping timeout: 246 seconds)
2021-03-12 22:19:19 <sparsity> and then you should be able to traverse over it
2021-03-12 22:19:55 <monochrom> infinisil: I think you have to roll your own. But you can copy someone else's code and modify it. http://hackage.haskell.org/package/generic-deriving has code using Generics to reinvent Show. You can steal that code and add your depth parameter.
2021-03-12 22:20:06 × hyperisco quits (~hyperisco@d192-186-117-226.static.comm.cgocable.net) (Ping timeout: 246 seconds)
2021-03-12 22:20:09 conal joins (~conal@184.170.243.131)
2021-03-12 22:20:59 <infinisil> Ah that sounds promising
2021-03-12 22:23:27 × Pickchea quits (~private@unaffiliated/pickchea) (Quit: Leaving)
2021-03-12 22:23:27 CrazyPython joins (~crazypyth@98.122.164.118)
2021-03-12 22:26:37 × sparsity quits (5ce955fb@gateway/web/cgi-irc/kiwiirc.com/ip.92.233.85.251) (Quit: Connection closed)
2021-03-12 22:27:49 × Narinas quits (~Narinas@187-178-93-112.dynamic.axtel.net) (Read error: Connection reset by peer)
2021-03-12 22:27:49 <dmj`> monochrom: interesting to note too, I don't believe the entire list is actually forced onto the heap during the call to (/), just the spine from length. Each cons cell progressively gets forced to a Double (when pattern-matched in sum), added, and then GC'd after the next recursive call. So if someone said, "The entire list is present on the heap" I'd say that might not be entirely accurate.
2021-03-12 22:28:08 Narinas joins (~Narinas@187-178-93-112.dynamic.axtel.net)
2021-03-12 22:28:47 <monochrom> Right.
2021-03-12 22:29:22 × CrazyPython quits (~crazypyth@98.122.164.118) (Remote host closed the connection)
2021-03-12 22:29:34 ericsagn1 joins (~ericsagne@2405:6580:0:5100:985d:1221:bd5b:d5dd)
2021-03-12 22:29:57 <Gurkenglas> Can I make an irrefutable pattern match with a custom error?

All times are in UTC.