Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,791,040 events total
2026-04-09 12:02:08 <mauke> import Debug.Trace (trace); x :: Int; x = trace "computing x" (4 + 1)
2026-04-09 12:02:21 <tomsmeding> apparently GHC does decide to keep `x` in your print x >> print x example; click Core here: https://play.haskell.org/saved/4XJoAJ1A
2026-04-09 12:02:41 uli-fem joins (~uli-fem@115.128.112.118)
2026-04-09 12:03:22 <tomsmeding> Milan_Vanca: the recursive function 'main' has a reference to x, and main stays alive (because it loops), so its reference to x also stays alive, so the GC does not remove x
2026-04-09 12:03:37 <mauke> also, x is a global variable
2026-04-09 12:03:43 <mauke> are those ever released?
2026-04-09 12:03:50 <tomsmeding> they can be, yes
2026-04-09 12:04:13 <merijn> mauke: Yes
2026-04-09 12:04:37 <merijn> mauke: It's a CAF, those can be GCed just fine if nothing references them anymore
2026-04-09 12:04:39 <tomsmeding> on a higher level: x is a monomorphic variable, so its value will live (once computed) until it goes out of scope -- or potentially for even longer if GHC decides so
2026-04-09 12:05:08 <tomsmeding> here x is a global variable, so it never goes out of scope, so it lives forever (until the GC decides that it's pointless keeping it around because nothing references it any more)
2026-04-09 12:07:42 <Milan_Vanca> Will https://paste.tomsmeding.com/XLBvdfd1 will x be in memory while one_hour_long computation runs?
2026-04-09 12:07:44 × uli-fem quits (~uli-fem@115.128.112.118) (Ping timeout: 268 seconds)
2026-04-09 12:08:02 <Milan_Vanca> Sorry to bother you with these stupid questions but I have found no tutorial on this matter.
2026-04-09 12:09:04 <Milan_Vanca> I gues compiler sees that x is not used after one_hour_long and so releases it as soon as it finish printing of x?
2026-04-09 12:09:12 <merijn> correct
2026-04-09 12:09:38 <merijn> Milan_Vanca: But that's pretty much how it works in any garbage collected languages, that's not really specific to Haskell :)
2026-04-09 12:09:58 <mauke> s/releases/makes available for release/
2026-04-09 12:10:09 machinedgod joins (~machinedg@d172-219-48-230.abhsia.telus.net)
2026-04-09 12:10:10 <mauke> haskell doesn't do timely destruction
2026-04-09 12:10:24 <merijn> mauke: Well, if you wanna be pedantic it's "no longer makes unavailable for release" ;)
2026-04-09 12:10:29 <mauke> :-)
2026-04-09 12:10:58 <Milan_Vanca> I am aware of GC and their purpose.. and all these questions stem from this fact :)
2026-04-09 12:11:36 <merijn> Milan_Vanca: Basically, GHC uses a "copy & compact" GC strategy. Which means it only cares (and scales in) live data
2026-04-09 12:12:13 <Milan_Vanca> Guyz.. what about this example https://paste.tomsmeding.com/TvkbD7xi
2026-04-09 12:12:16 <merijn> Milan_Vanca: Once the heap is full and GC is triggered it copies all live data (that is, data that is still reachable from the currently evaluating code) and copies that to a new heap. Then the old heap is reset
2026-04-09 12:12:47 <merijn> Milan_Vanca: 'x' becomes unreachable (an thus GC-able) after the first 30 minutes elapse
2026-04-09 12:14:28 <Milan_Vanca> So x is computed once and kept for first 30 mins..hmmmm.. interesting.
2026-04-09 12:14:56 <Milan_Vanca> It knows it can reuse the same x even when it is in different function
2026-04-09 12:16:05 × synchromesh quits (~john@2406:5a00:2412:2c00:8174:9ae9:efe0:c152) (Read error: Connection reset by peer)
2026-04-09 12:16:35 synchromesh joins (~john@2406:5a00:2412:2c00:e029:fa8c:cb38:398f)
2026-04-09 12:19:49 <merijn> Milan_Vanca: It helps to think of a haskell program as a data structure that is mutated
2026-04-09 12:19:50 <Milan_Vanca> Does it matter if X is defined in another module?
2026-04-09 12:19:55 <merijn> Milan_Vanca: No
2026-04-09 12:21:16 uli-fem joins (~uli-fem@115.128.112.118)
2026-04-09 12:21:57 <merijn> Milan_Vanca: basically we start out with a graph of expressions with main as root, which references x and 'one_hour_long', where 'one_hour_long' in turn also references x (which is a subgraph of '4' '+' and '1'), as code gets evaluated these graphs expand and collapse as we force new computation. Starting to evaluate 'x' first materialises this subgraph of 4+1, once that evaluation is complete 'x' just
2026-04-09 12:22:03 <merijn> refers to the result (regardless of how you reach x)
2026-04-09 12:22:33 <merijn> Milan_Vanca: Eventually as evaluation procedes parts of the original graph become unreachable (and thus eligible for GC)
2026-04-09 12:24:05 <merijn> a thunk is just "some computation that unfolds into a (sub)graph" and evaluation is "collapsing a graph into a result"
2026-04-09 12:25:22 × CiaoSen quits (~Jura@p549cb690.dip0.t-ipconnect.de) (Ping timeout: 248 seconds)
2026-04-09 12:25:24 × Googulator quits (~Googulato@94-21-172-213.pool.digikabel.hu) (Quit: Client closed)
2026-04-09 12:25:26 × qqq quits (~qqq@185.54.23.237) (Remote host closed the connection)
2026-04-09 12:25:32 Googulator joins (~Googulato@94-21-172-213.pool.digikabel.hu)
2026-04-09 12:27:29 <ski> @where lazy
2026-04-09 12:27:30 <lambdabot> "Lazy Evaluation of Haskell" by monochrom at <http://www.vex.net/~trebla/haskell/lazy.xhtml>; "The Incomplete Guide to Lazy Evaluation (in Haskell)" by apfelmus in 2015-03-07 at <https://apfelmus.
2026-04-09 12:27:30 <lambdabot> nfshost.com/articles/lazy-eval.html>; "Laziness, strictness, guarded recursion" by bitemyapp at <https://github.com/bitemyapp/learnhaskell/blob/master/specific_topics.md#user-content-laziness-
2026-04-09 12:27:30 <lambdabot> strictness-guarded-recursion>
2026-04-09 12:27:33 <ski> Milan_Vanca ^
2026-04-09 12:28:07 <Milan_Vanca> Ty all :) I am gonna also read that link
2026-04-09 12:31:20 tremon joins (~tremon@83.80.159.219)
2026-04-09 12:34:21 <merijn> Milan_Vanca: What's your background?
2026-04-09 12:34:38 <merijn> i.e. what languages are you experienced with, etc.?
2026-04-09 12:35:53 <Milan_Vanca> merijn: Mostly procedural ones. Haskell is my first attempt at FP
2026-04-09 12:36:32 <merijn> Milan_Vanca: If you're comfortable with C and some assembly I've always found that STG paper rather enlightening
2026-04-09 12:37:39 <merijn> Milan_Vanca: The essence of that paper is "how do you compile Haskell's lazy semantics to x86 hardware", which covers a lot low level details related to how GHC compiled Haskell actually runs
2026-04-09 12:37:43 <merijn> @where stg
2026-04-09 12:37:44 <lambdabot> https://dl.acm.org/doi/pdf/10.1145/99370.99385
2026-04-09 12:38:51 <Milan_Vanca> I think reading code yields the most insights but one can pick implementation details that are more GHC than haskell
2026-04-09 12:39:40 <Milan_Vanca> Btw haskell spec probably doesn't say anything about keeping values and reevaluating them right? If my implementation would always reevaluate everything then would it be valid haskell implementation?
2026-04-09 12:46:03 haritzondo joins (~hrtz@140.228.70.141)
2026-04-09 12:46:08 × haritz quits (~hrtz@user/haritz) (Ping timeout: 252 seconds)
2026-04-09 12:49:37 karenw joins (~karenw@user/karenw)
2026-04-09 12:51:52 castan joins (~castan@188.26.38.50)
2026-04-09 12:55:06 × castan quits (~castan@188.26.38.50) (Client Quit)
2026-04-09 12:55:44 × Enrico63 quits (~Enrico63@host-212-171-80-94.pool212171.interbusiness.it) (Quit: Client closed)
2026-04-09 12:55:45 × poscat quits (~poscat@user/poscat) (Remote host closed the connection)
2026-04-09 12:56:09 poscat joins (~poscat@user/poscat)
2026-04-09 12:56:36 <janus> yay, gershom merged my patch for hackage, now only authorized users can update distro information
2026-04-09 12:57:41 × uli-fem quits (~uli-fem@115.128.112.118) (Ping timeout: 252 seconds)
2026-04-09 13:11:39 uli-fem joins (~uli-fem@115.128.112.118)
2026-04-09 13:16:31 × uli-fem quits (~uli-fem@115.128.112.118) (Ping timeout: 264 seconds)
2026-04-09 13:17:31 × lbseale quits (~quassel@user/ep1ctetus) (Quit: https://quassel-irc.org - Chat comfortably. Anywhere.)
2026-04-09 13:17:59 lbseale joins (~quassel@user/ep1ctetus)
2026-04-09 13:29:47 uli-fem joins (~uli-fem@115.128.112.118)
2026-04-09 13:30:39 × gmg quits (~user@user/gehmehgeh) (Remote host closed the connection)
2026-04-09 13:33:29 gmg joins (~user@user/gehmehgeh)
2026-04-09 13:34:30 × uli-fem quits (~uli-fem@115.128.112.118) (Ping timeout: 255 seconds)
2026-04-09 13:46:27 fp1 joins (~Thunderbi@staff236.kora-dyn.aalto.fi)
2026-04-09 13:46:39 <merijn> Milan_Vanca: Yes, it would be
2026-04-09 13:50:14 danza joins (~danza@user/danza)
2026-04-09 13:59:26 uli-fem joins (~uli-fem@115.128.112.118)
2026-04-09 14:05:44 × uli-fem quits (~uli-fem@115.128.112.118) (Ping timeout: 245 seconds)
2026-04-09 14:12:09 synchrom1 joins (~john@2406:5a00:2412:2c00:e029:fa8c:cb38:398f)
2026-04-09 14:15:13 × synchromesh quits (~john@2406:5a00:2412:2c00:e029:fa8c:cb38:398f) (Ping timeout: 276 seconds)
2026-04-09 14:17:57 uli-fem joins (~uli-fem@115.128.112.118)
2026-04-09 14:22:31 sam113102 joins (~sam@modemcable200.189-202-24.mc.videotron.ca)
2026-04-09 14:22:57 × uli-fem quits (~uli-fem@115.128.112.118) (Ping timeout: 265 seconds)
2026-04-09 14:24:42 <Freakie> does anyone know of a way to redirect output to stdout? QuickCheck seems to only want to report results directly to the terminal but I'd like to save the results to a file instead
2026-04-09 14:26:47 absence_ joins (torgeihe@hildring.pvv.ntnu.no)
2026-04-09 14:26:58 lantti_ joins (~lantti@xcalibur.cc.tut.fi)
2026-04-09 14:27:45 <danza> > and 2> in bash?
2026-04-09 14:27:46 <lambdabot> <hint>:1:8: error: parse error on input `in'
2026-04-09 14:27:58 nurupo_ joins (~nurupo.ga@user/nurupo)
2026-04-09 14:28:07 thaumavorio joins (~thaumavor@thaumavor.io)
2026-04-09 14:29:35 <Freakie> danza if it works it's going to include a lot of noise from e.g. compiler output as well
2026-04-09 14:30:54 × bitdex quits (~bitdex@gateway/tor-sasl/bitdex) (Quit: = "")
2026-04-09 14:31:00 × karenw quits (~karenw@user/karenw) (Ping timeout: 245 seconds)
2026-04-09 14:31:18 <danza> yep. Maybe the answer depends on the test framework you run quickcheck into
2026-04-09 14:31:39 × fp1 quits (~Thunderbi@staff236.kora-dyn.aalto.fi) (Ping timeout: 255 seconds)
2026-04-09 14:32:23 <danza> my test suite based on Hspec saves a log when successful

All times are in UTC.