[Haskell-cafe] Why doesn't this consume all the computer's memory?
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Tue Nov 6 12:06:56 UTC 2018
Bertram Felgenhauer via Haskell-Cafe wrote:
> Tyson Whitehead wrote:
> > and, in the -ddump-simpl we see the `go Left` branch returns a thunk
> > on both the right and left sides that hold onto the evaluation of
> > (x:xs,ys) as we would expect
> >
> > ```
> > Left x_aqy ->
> > (GHC.Types.:
> > @ a_a1q8 x_aqy
> > (case ds1_d1rO of { (xs_aqz, ys_aqA) -> xs_aqz }),
> > case ds1_d1rO of { (xs_aqz, ys_aqA) -> ys_aqA });
> > ```
>
> These two expressions are selectors (accessing a field from a single
> constructor data type), which the compiler recoginizes (not sure where
> and how exactly) and implemented in terms of special stg_sel_<nnn>
> closures. At runtime, applying such a closure results in special
> THUNK_SELECTOR thunks. These thunks are evaluated by the garbage
> collector (see rts/sm/Scav.c).
Or rather rts/sm/Evac.c, which has functions unchain_thunk_selectors()
and eval_thunk_selector() that do the actual work.
Cheers,
Bertram
More information about the Haskell-Cafe
mailing list