📜 ⬆️ ⬇️

Haskell Heap


A bunch of Haskell is a pretty weird place. It does not look like a bunch in traditional language with rigorous calculations ...

... which is a bunch of garbage from good old simple data!

In a bunch of Haskell everything is neatly wrapped in boxes. A bunch of Haskell is a bunch of gifts (thunks).

When you want to know what is inside a gift, you open (calculate) it.

Gifts are usually somehow called, and sometimes, opening a gift, you get a gift certificate (data designer). The certificate has two features: it is somehow called (for example, Just or Right ), and it tells you where your gift is. And if you're lucky, there may even be a few gifts inside (certificate-tuple)!


You are not required to pick up your gift, as well as use a certificate, on which companies, by the way, earn good money!
The gifts in the pile are pretty capricious. Some explode when you open them, others are populated with spirits that open other gifts when they are disturbed.

Understanding what happens when you open a gift is the key to understanding how Haskell programs waste memory and time.

In this series of articles, Edward plunges you into the world of comics to show the basics of computing in a lazy language. I hope you will like it!
Next time: Calculation in a Haskell heap
Comment. Strictly speaking, this series should be called “Heap GHC”. But I tried to remove as many dependencies from GHC as possible and suggest a metaphor that applies to any lazy language. Initially, the series was titled “Demoman studying lazy calculations”, but I have a bomb metaphor for thunks that give an error or hang. I prefer the gift metaphor, as it captures several important aspects of laziness: the difference between the calculated / non-calculated and the fact that once an open gift is open to everyone. The use of the term “boxed” is a little confusing: the boxed or lifted values ​​in GHC may hang or generate an error, while the unboxed values ​​are similar to what you see in the C language heap. However, languages ​​like Java also use boxed for primitive values ​​that look like objects. For clarity, from now on we will not use the term boxed (and, of course, do not consider unboxed types).

')

Source: https://habr.com/ru/post/118797/


All Articles