<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Two questions here, I think they might be related, perhaps even the same, but I am not sure, so I will ask both:<br><br>Q1:&nbsp; Re the function f below, I like the first implementation as it's "cleaner", but is the second implementation necessary for performance purposes?<br><br>-- g = some CPU intensive function<br><br>-- alternate 1<br>f a b = c + (g b)<br>&nbsp;&nbsp;&nbsp; where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = dosomethingelse a (g b)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>-- alternate 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>f a b = c + saveit<br>&nbsp;&nbsp;&nbsp; where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; saveit = g b&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = dosomethingelse a saveit<br><br><br>Q2:&nbsp; Imagine that I might be creating a custom data structure.&nbsp; I need to
 access both the data in that structure, but also "features" (don't know proper comp sci term) of the data structure.&nbsp; For instance, consider a Haskell list.&nbsp; The stuff in the list is the data, whereas the length of the list is what I am calling a "feature" here.&nbsp; Some of my features might be quite a bit more computationally intensive than "length", and may be referenced multiple times in many different places in my code.&nbsp; For performance purposes, should I consider modifying my data structure to embed these "features" as part of the data to ensure that it is only calculated once?&nbsp; Or can I rely on Haskell to do that for me?&nbsp; For instance, do I need to create the equivalent of:<br><br>data MyList a = MyList {mylist::[a], mylength::Int}<br><br><br><br>Thanks again for all your generous advice.<br></td></tr></table><br>