How does Haskell manage its memory?











up vote
1
down vote

favorite
1












So, we know that for most languages, throughout a program's execution:




  • Global variables are stored in static memory.

  • Local variables are stored in the stack memory.

  • Arbitrarily-changing variables are stored in the heap.


What about Haskell? All I know is that it is lazy. How does that translate into this context?










share|improve this question









New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 5




    Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
    – Willem Van Onsem
    2 days ago






  • 3




    As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
    – leftaroundabout
    2 days ago








  • 2




    Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g. sbrk) or heap (mmap), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
    – chi
    2 days ago






  • 2




    Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
    – chepner
    2 days ago















up vote
1
down vote

favorite
1












So, we know that for most languages, throughout a program's execution:




  • Global variables are stored in static memory.

  • Local variables are stored in the stack memory.

  • Arbitrarily-changing variables are stored in the heap.


What about Haskell? All I know is that it is lazy. How does that translate into this context?










share|improve this question









New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 5




    Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
    – Willem Van Onsem
    2 days ago






  • 3




    As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
    – leftaroundabout
    2 days ago








  • 2




    Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g. sbrk) or heap (mmap), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
    – chi
    2 days ago






  • 2




    Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
    – chepner
    2 days ago













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





So, we know that for most languages, throughout a program's execution:




  • Global variables are stored in static memory.

  • Local variables are stored in the stack memory.

  • Arbitrarily-changing variables are stored in the heap.


What about Haskell? All I know is that it is lazy. How does that translate into this context?










share|improve this question









New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











So, we know that for most languages, throughout a program's execution:




  • Global variables are stored in static memory.

  • Local variables are stored in the stack memory.

  • Arbitrarily-changing variables are stored in the heap.


What about Haskell? All I know is that it is lazy. How does that translate into this context?







haskell memory-management functional-programming ghc






share|improve this question









New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 12 hours ago









Benjamin Hodgson

26.2k1172121




26.2k1172121






New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









thlik

93




93




New contributor




thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






thlik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 5




    Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
    – Willem Van Onsem
    2 days ago






  • 3




    As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
    – leftaroundabout
    2 days ago








  • 2




    Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g. sbrk) or heap (mmap), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
    – chi
    2 days ago






  • 2




    Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
    – chepner
    2 days ago














  • 5




    Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
    – Willem Van Onsem
    2 days ago






  • 3




    As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
    – leftaroundabout
    2 days ago








  • 2




    Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g. sbrk) or heap (mmap), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
    – chi
    2 days ago






  • 2




    Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
    – chepner
    2 days ago








5




5




Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago




Well a lot of (high-level) languages keep it open how memory management is implemented. But for GHC, this wiki page might be a start.
– Willem Van Onsem
2 days ago




3




3




As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago






As a zeroth-order approximation you'd have to say that everything is on the heap in Haskell, but more practically we can assume that the compiler will decide to put any variable whereever it's deemed best for performance. Quite often it will also eliminate variables entirely, or introduce new ones. All that the language specifies is that you'll get the right results in the end...
– leftaroundabout
2 days ago






2




2




Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g. sbrk) or heap (mmap), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
– chi
2 days ago




Don't forget that static/stack/heap memory does not really exist on its own. At the lower level, we only have RAM (including virtual memory). Then the OS may reserve a portion of the address space for the "stack", allow processes to request more stack (e.g. sbrk) or heap (mmap), and pre-allocating a static portion when the executable is loaded. The the language runtime system can, on top of this, use garbage collection. Some variants of GC further divide the memory into generations or from-space/to-space (for copying GCs). These are further abstractions, usually implemented in the "heap"
– chi
2 days ago




2




2




Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago




Haskell doesn't say anything about memory management. A particular implementation of Haskell makes those decisions.
– chepner
2 days ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






thlik is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238460%2fhow-does-haskell-manage-its-memory%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








thlik is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















thlik is a new contributor. Be nice, and check out our Code of Conduct.













thlik is a new contributor. Be nice, and check out our Code of Conduct.












thlik is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238460%2fhow-does-haskell-manage-its-memory%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values