Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy directly imported functions in GHC differ so much with functions I write with the source code copied from GHC Libraries
    text
    copied!<pre><code>module Has (r,p,s) where import Prelude ((==),Bool(..),otherwise,(||),Eq) import qualified Data.List as L filter :: (a -&gt; Bool) -&gt; [a] -&gt; [a] filter _pred [] = [] filter pred (x:xs) | pred x = x : filter pred xs | otherwise = filter pred xs </code></pre> <p>problem1: This <code>filter</code> is copied from <code>GHC</code>'s library, but why it consumes a growing number of memory <em>in contrast with</em> the directly imported <code>filter</code>, which consumes a constant number of memory.</p> <pre><code>elem :: (Eq a) =&gt; a -&gt; [a] -&gt; Bool elem _ [] = False elem x (y:ys) = x==y || elem x ys </code></pre> <p>problem2: This <code>filter</code> is copied from <code>GHC</code>'s library, but why it consumes a growing number of memory <em>like</em> the directly used <code>elem</code>, which <em>also</em> consumes a growing number of memory <em>in contrast with</em> the directly imported <code>filter</code>.</p> <pre><code>r = L.filter (==1000000000000) [0..] p = filter (==1000000000000) [0..] s = 1000000000000 `elem` [0..] </code></pre> <p>GHC version:7.4.2 OS:Ubuntu 12.10 Compiled with -O2 to optimize</p> <p>As the above <code>filter</code> and <code>elem</code> 's definitions imply both <code>p = filter (==1000000000000) [0..]</code> and <code>s = 1000000000000 `elem` [0..]</code> 's <code>[0..]</code> should be garbage collected gradually. But both <code>p</code> and <code>s</code> consumes a growing number of memory. And <code>r</code> which is defined with the directly imported <code>filter</code> consumes a constant number of memory.</p> <p>My question is why directly imported functions in GHC differ so much with functions I write with the source code copied from GHC Libraries. I wonded if there is something wrong with GHC?</p> <p>I has a further question: The above code is abstracted from a project I writed, and the project also faces the problem of "consumes a growing number of memory, which should be garbage collected in theory". So I want to know that is there a way to find which variable takes up so much memory in GHC.</p> <p>Thanks for your reading.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload