<div dir="ltr"><div class="gmail_default" style="font-family:times new roman,serif;font-size:large">Agreed!</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">Thanks</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 Sat, May 18, 2024 at 3:43 AM Tom Ellis <<a href="mailto:tom-lists-haskell-cafe-2023@jaguarpaw.co.uk">tom-lists-haskell-cafe-2023@jaguarpaw.co.uk</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">I don't think optimization plays any role.  At the start of the<br>
program 'norm' is a thunk which points to the code 'trace "norm" id'.<br>
The first time it is evaluated the 'trace' prints "norm" and 'norm'<br>
becomes bound to the value 'id'.<br>
<br>
On Fri, May 17, 2024 at 08:26:44PM -0300, George Colpitts wrote:<br>
> Thanks Henning! I suspected some kind of optimization but I didn't think<br>
> ghci would do any. I guess it is just a subtle consequence of eta<br>
> reduction. It was very confusing to me.<br>
> <br>
> On Fri, May 17, 2024 at 6:43 PM Henning Thielemann <<br>
> <a href="mailto:lemming@henning-thielemann.de" target="_blank">lemming@henning-thielemann.de</a>> wrote:<br>
> <br>
> ><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<br>
> > "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<br>
> > /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<br>
_______________________________________________<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>