Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This value <code>squares</code> is potentially polymorphic:</p> <pre><code>Prelude&gt; :t [ x ** 2 | x &lt;- [1 ..] ] [ x ** 2 | x &lt;- [1 ..] ] :: (Floating t, Enum t) =&gt; [t] </code></pre> <p>AFAIK, whether or not it will be recalculated (in GHC) depends on whether the top-level value <code>squares</code> is given a polymorphic type. I believe that GHC does not do any memoization of polymorphic values involving type classes (functions from types to values), just as it does not do any memoization of ordinary functions (functions from values to values).</p> <p>That means if you define <code>squares</code> by</p> <pre><code>squares :: [Double] squares = [ x ** 2 | x &lt;- [1 ..] ] </code></pre> <p>then <code>squares</code> will only be computed once, while if you define it by</p> <pre><code>squares :: (Floating t, Enum t) =&gt; [t] squares = [ x ** 2 | x &lt;- [1 ..] ] </code></pre> <p>then it will likely be computed each time it is used, even if it's used repeatedly at the same type. (I haven't tested this, though, and it's possible that GHC, if it sees several uses of <code>squares :: [Double]</code>, could specialize the <code>squares</code> value to that type and share the resulting value.) Certainly if <code>squares</code> is used at several different types, like <code>squares :: [Double]</code> and <code>squares :: [Float]</code>, it will be recalculated.</p> <p>If you don't give any type signature for <code>squares</code>, then the <a href="http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-930004.5.5" rel="noreferrer">monomorphism restriction</a> will apply to it, unless you have it disabled. The result will be that <code>squares</code> is assigned a monomorphic type, inferred from the rest of your program (or according to the defaulting rules). The purpose of the monomorphism restriction is exactly to ensure that values that look like they will only be evaluated once, such as your <code>squares</code>, really will only be evaluated once.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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