<div dir="ltr">It's a consequence of lazy evaluation. Which means `trace` is very useful to see when things are actually evaluated, but not useful as a general output mechanism.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 17, 2024 at 7:27 PM George Colpitts <<a href="mailto:george.colpitts@gmail.com">george.colpitts@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:"times new roman",serif;font-size:large">Thanks Henning! I suspected some kind of optimization but I didn't think ghci would do any. I guess it is just a subtle consequence of eta reduction. It was very confusing to me.</div><div class="gmail_default" style="font-family:"times new roman",serif;font-size:large"><br></div><div class="gmail_default" style="font-family:"times new roman",serif;font-size:large">Cheers</div><div class="gmail_default" style="font-family:"times new roman",serif;font-size:large">George</div><div class="gmail_default" style="font-family:"times new roman",serif;font-size:large"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 17, 2024 at 6:43 PM Henning Thielemann <<a href="mailto:lemming@henning-thielemann.de" target="_blank">lemming@henning-thielemann.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On Fri, 17 May 2024, George Colpitts wrote:<br>
<br>
> After I load the following into ghci and call main I expect to see "norm" in the output 3 times as I have called it 3 times<br>
> but it only shows once. Why?<br>
> <br>
> traceBug.hs<br>
> ---------------<br>
> {-# OPTIONS_GHC -Wall #-}<br>
> <br>
> import Debug.Trace (trace)<br>
> <br>
> norm :: [Int] -> [Int]<br>
> norm = trace ("norm") id<br>
> <br>
> main :: IO ()<br>
> main =<br>
> do<br>
> print $ norm [2]<br>
> print $ norm [2]<br>
> print $ norm [3]<br>
> ---------------------<br>
> <br>
> ghci session<br>
> <br>
> % ghci traceBug.hs<br>
> Loaded package environment from /Users/gcolpitts/.ghc/x86_64-darwin-9.8.2/environments/default<br>
> GHCi, version 9.8.2: <a href="https://www.haskell.org/ghc/" rel="noreferrer" target="_blank">https://www.haskell.org/ghc/</a> :? for help<br>
> [1 of 2] Compiling Main ( traceBug.hs, interpreted )<br>
> Ok, one module loaded.<br>
> ghci> main<br>
> norm<br>
> [2]<br>
> [2]<br>
> [3]<br>
<br>
<br>
I think this is correct. 'norm' is evaluated only once, because it is the <br>
same variable (for a function) in every call. It would be different, if <br>
you would define:<br>
<br>
norm xs = trace "norm" xs</blockquote></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>