Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,802,492 events total
2025-11-21 02:54:56 <monochrom> I don't think professional Haskellers use [] as a data structure at all. They use it as for loops. Then caching lengths becomes the stupid one.
2025-11-21 02:55:03 <EvanR> since stuff like elixir doesn't have
2025-11-21 02:55:20 <EvanR> that
2025-11-21 02:55:47 <jreicher> Oh you're right. Elixir doesn't do this either. I didn't know.
2025-11-21 02:56:08 jmcantrell joins (~weechat@user/jmcantrell)
2025-11-21 02:56:11 <probie> You're also calling `collatz` a lot of times; Your `maximumBy` will invoke it twice at each comparison
2025-11-21 02:56:31 <monochrom> or perhaps s/at all/seriously/ . E.g., short lists outside hotspots still happen.
2025-11-21 02:58:36 <EvanR> I'm kind of surprised the elixir code doesn't stack over flow with that kind of eager evaluation and recursion
2025-11-21 02:58:45 <jreicher> sam113101: why are you computing (and keeping) the chain? Why not just do the count as you go?
2025-11-21 02:58:52 × merijn quits (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 264 seconds)
2025-11-21 02:58:54 <haskellbridge> <sm> you could add trace logging to both and it might show how much more work the haskell is doing
2025-11-21 02:59:07 <haskellbridge> <sm> also you could profile it
2025-11-21 02:59:18 <EvanR> yes there are more efficient ways to do this but the idea was the compare the "same algorithm" (ignoring the difference in evaluation strategy) in the two languages
2025-11-21 02:59:22 <EvanR> which we haven't actually seen yet
2025-11-21 02:59:25 <sam113101> jreicher: that's the way I've done it the first time and now I'm comparing languages/runtimes with the same algorithm
2025-11-21 02:59:33 <EvanR> show the haskell code
2025-11-21 03:00:04 <fgarcia> for the clauses, i wasn't sure what it did at first. you might like 'collatzChain lst@(1:_) = lst' as a pattern match
2025-11-21 03:00:07 <monochrom> I do wish GHC allowed multiple-module files.
2025-11-21 03:00:28 <monochrom> or any Haskell implementation
2025-11-21 03:01:47 <EvanR> on line 10 in the haskell version, you should explicitly evaluate nextCollatz x before prepending it to the list
2025-11-21 03:02:02 <EvanR> otherwise you're tacking on a thunk that will be evaluated later
2025-11-21 03:02:11 <EvanR> which has a cost and is unnecessary
2025-11-21 03:03:10 <EvanR> this would be automatic in elixir
2025-11-21 03:03:10 <probie> monochrom: I think it does, via bkp files (if that hasn't been removed yet)
2025-11-21 03:03:11 <fgarcia> oh that might be something like flip (:) lst $! nextCollatz x
2025-11-21 03:03:42 <monochrom> Probably not. the "x==1" test that happens right away will evaluate it. With -O1, the strictness analyzer will notice that and kill the laziness altogether. We can check this...
2025-11-21 03:03:44 <jreicher> EvanR: how is that automatic in Elixir?
2025-11-21 03:03:55 <EvanR> it's an eager language
2025-11-21 03:04:06 <EvanR> monochrom, oh...
2025-11-21 03:04:06 <jreicher> Oh. :)
2025-11-21 03:04:45 <EvanR> still worth a shot because the field is full of dead attempts to predict what GHC does
2025-11-21 03:05:58 <EvanR> I refuse to say more until I see the properly
2025-11-21 03:06:08 <EvanR> evaluation
2025-11-21 03:06:20 <EvanR> I refuse to say more until I see the two programs properly compared
2025-11-21 03:07:01 <jreicher> I also have no idea how much static analysis either language can do; they might figure out the list is actually discarded.
2025-11-21 03:07:46 <jreicher> And for that reason I really wouldn't code this with a list.
2025-11-21 03:08:29 <fgarcia> i think ghc might be detecting a lot of things. it would warn me about changing 'collatzChain lst@(x:xs)' to 'collatzChain lst@(x:_)' because xs it not used
2025-11-21 03:09:15 <c_wraith> It's worth spending some time learning about things that are easy to detect vs things that are hard to detect.
2025-11-21 03:09:16 merijn joins (~merijn@host-vr.cgnat-g.v4.dfn.nl)
2025-11-21 03:09:30 <c_wraith> It's easy to detect a symbol is bound and not used.
2025-11-21 03:09:59 <c_wraith> It's a lot harder to do flow analysis to determine usage patterns across recursive calls
2025-11-21 03:10:00 <monochrom> Is it just because GHC uses multi-precision integers and Elixir uses 32-bit or 64-bit?
2025-11-21 03:10:30 <EvanR> xs not used, it's not even clear how it could compile that in any other way than "not"
2025-11-21 03:10:59 <probie> monochrom: I know this isn't actually what you want, but https://paste.tomsmeding.com/oqM6JwKf
2025-11-21 03:11:33 <fgarcia> making a collatzChain' with an accumulator might speed things up but i am not sure
2025-11-21 03:11:37 <EvanR> elixir's "int" or whatever it's called is notionally unlimited precision
2025-11-21 03:12:05 <EvanR> and does collatz grow large enough to matter (and leave the small int case of Integer's backend)
2025-11-21 03:12:11 <monochrom> Oh I didn't know that backpack can do that. :)
2025-11-21 03:14:41 <monochrom> Yikes, core says not evaluated until next time it hits the x==1 test.
2025-11-21 03:15:08 <EvanR> it could be worse
2025-11-21 03:15:11 <monochrom> Although, I would bet it only causes 2->4 not 2->30.
2025-11-21 03:15:31 <sam113101> I got it dows to 6s with -O2
2025-11-21 03:15:45 × merijn quits (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 245 seconds)
2025-11-21 03:16:01 <EvanR> that was my first suggestion! smh
2025-11-21 03:17:02 <Leary> sam113101: Next suggestion: write some type signatures. Believe it or not, they make your code faster.
2025-11-21 03:17:10 <monochrom> What is Enum.count in Elixir?
2025-11-21 03:17:24 <EvanR> for lists it will count the elements
2025-11-21 03:17:32 <EvanR> of a linked list
2025-11-21 03:18:40 <Leary> (the compiler can infer types, but that doesn't mean it can read your mind to infer the type you wanted to use)
2025-11-21 03:19:38 fgarcia hides code without signatures
2025-11-21 03:20:06 × chromoblob quits (~chromoblo@user/chromob1ot1c) (Ping timeout: 265 seconds)
2025-11-21 03:20:39 × Googulator87 quits (~Googulato@2a01-036d-0106-0231-4475-80b4-5cdc-43d6.pool6.digikabel.hu) (Quit: Client closed)
2025-11-21 03:20:44 chromoblob joins (~chromoblo@user/chromob1ot1c)
2025-11-21 03:20:44 Googulator96 joins (~Googulato@2a01-036d-0106-0231-4475-80b4-5cdc-43d6.pool6.digikabel.hu)
2025-11-21 03:20:46 <sam113101> Executed in 1.36 secs
2025-11-21 03:20:50 <sam113101> wow it really did
2025-11-21 03:20:58 <EvanR> I delete all my type signatures, dare the compiler to do what I mean, without even my knowing what I mean
2025-11-21 03:21:41 × vanishingideal quits (~vanishing@user/vanishingideal) (Ping timeout: 264 seconds)
2025-11-21 03:22:18 <monochrom> Is that just because you say "Int" not "Integer"?
2025-11-21 03:22:48 <sam113101> I did use Int, not sure if the compiler defaulted to Integer?
2025-11-21 03:23:05 vanishingideal joins (~vanishing@user/vanishingideal)
2025-11-21 03:23:13 <monochrom> Without type signature, everything resolves to Integer. And monomorphized. (I checked the Core code.)
2025-11-21 03:23:23 <monochrom> Yes default Integer.
2025-11-21 03:24:34 <fgarcia> Do as I say. delete cosmic!
2025-11-21 03:25:15 <monochrom> "permission denied"
2025-11-21 03:25:35 <monochrom> You have to say: sudo delete cosmic and make me a sandwich :)
2025-11-21 03:26:06 <fgarcia> gah why is it so hard to install steam
2025-11-21 03:26:39 <monochrom> Fun fact: Curry has Int, it already means multi-precision. There is no bounded integer type in Curry. :)
2025-11-21 03:27:20 merijn joins (~merijn@host-vr.cgnat-g.v4.dfn.nl)
2025-11-21 03:29:10 <EvanR> bounded integer is a contradiction extraordinaire
2025-11-21 03:29:12 <monochrom> Also, Float is already double-precision, it is the only floating point type.
2025-11-21 03:29:21 <EvanR> not to be confused with modular integers
2025-11-21 03:29:35 <EvanR> or Fin n
2025-11-21 03:29:41 <EvanR> *nor
2025-11-21 03:30:14 <EvanR> the certain good applications that exist for single precision are sad
2025-11-21 03:30:21 <EvanR> with curry
2025-11-21 03:30:45 <EvanR> but going from 1/2 number types to any number of number types is definitely a jump
2025-11-21 03:31:01 <fgarcia> does Fractional work? i think it has Float and Double
2025-11-21 03:32:06 × merijn quits (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 256 seconds)
2025-11-21 03:32:44 × annamalai quits (~annamalai@2409:4042:4e39:7842::9e0a:bf0a) (Read error: Connection reset by peer)
2025-11-21 03:32:58 annamalai joins (~annamalai@2409:4042:4e39:7842::9e0a:bf0a)
2025-11-21 03:35:41 <monochrom> Fractional works but there is only one instance.
2025-11-21 03:36:33 <EvanR> > 100 / 3 :: Centi
2025-11-21 03:36:35 <lambdabot> 33.33
2025-11-21 03:36:45 <EvanR> we have more instances
2025-11-21 03:37:07 trickard_ is now known as trickard
2025-11-21 03:37:17 qqe joins (~qqq@185.54.21.140)
2025-11-21 03:39:10 <monochrom> Yeah Haskell has more adoption and more contributors :)
2025-11-21 03:41:12 <EvanR> oh, curry has few instances just because lack of effort, and not to simplify things?
2025-11-21 03:42:04 × aditya_an1l quits (~aditya_an@user/aditya-an1l:63825) (Ping timeout: 264 seconds)

All times are in UTC.