<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">That’s true, I also discovered the case, where the enum has a reference type as an associated value, which is then modified by a function. Such a function would clearly not be pure either, so a pure function should not be able to capture from a different scope and should not be able to access reference types. I see the problem there.<div class="">But with the workarounds for memoization there is still a problem with enums: As enums cannot have stored properties, it is not possible to create a constant closure in the enum. Isn’t this somehow a inconsistency that I can’t write</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Test {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo = {</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">but I can write</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Test {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo() -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">For this I would have two possible solutions: Allow assigning to a function somehow like this:</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo = {</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div></div><div class=""><br class=""></div><div class="">Or allowing constants in enums as a constant would not be anything else than an associated type with a possible default value, which every case of the enum contains.</div><div class=""><br class=""></div><div class="">But I see this is out of scope for this discussion and I will look for other ways for memoization on swift-users.</div><div class=""><br class=""></div><div class="">Thanks</div><div class="">Tierry Hoermann</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 25 Apr 2017, at 19:47, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Well, first, let's address some misconceptions in Tierry's email:<br class=""></div><div class=""><br class=""></div><div class=""><span style="background-color:rgb(253,253,253)" class="">"E</span><span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)" class="">nums in swift are purely functional and therefore functions without parameters always return the same value in an enum"...is not true. A function without parameters can have any amount of side effects and can return a random value or a copy of a global variable.</span><br class=""></div><div class=""><span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)" class=""><br class=""></span></div><div class=""><span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)" class="">There are some nice designs out there for memoization in Swift. I recall one in the excellent Advanced Swift, but I could be remembering another source. I'd suggest a discussion on swift-users.</span></div><div class=""><span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)" class=""><br class=""></span></div><div class=""><span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)" class="">But yes, pure functions are some ways off.</span></div><div class=""><span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><div class="gmail_quote"><div class="">On Tue, Apr 25, 2017 at 12:19 David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class=""><br class=""><br class="">Sent from my iPhone</div></div><div class=""><div class=""><br class="">On Apr 25, 2017, at 06:44, Tierry Hörmann via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class="">Hi all<div class=""><br class=""></div><div class="">I discovered that memoization is currently a pain to implement when using functional programming.</div><div class="">E.g. when implementing a lazy linked list, one obviously uses an enum to represent the data. But there is also a wrapper struct needed with lazy variables (especially a lazy property tail), as enums can not have stored properties. Here some example code of such a lazy linked list:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">struct</span><span style="font-variant-ligatures:no-common-ligatures" class=""> LazyList&lt;T&gt; {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> root: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LLE</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="m_1189542397825839138m_-5679191037068719472webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> root: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LLE</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;&nbsp;= </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LLE</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">End</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">root</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = root</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="m_1189542397825839138m_-5679191037068719472webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hd: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">? {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">get</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">root</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">val</span><span style="font-variant-ligatures:no-common-ligatures" class="">()}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="m_1189542397825839138m_-5679191037068719472webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="m_1189542397825839138m_-5679191037068719472webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">lazy</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">private</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> tail: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LLE</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt; = </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">root</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">tail</span><span style="font-variant-ligatures:no-common-ligatures" class="">()()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> tl: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LazyList</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt; {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">mutating</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">get</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LazyList</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">tail</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">enum</span><span style="font-variant-ligatures:no-common-ligatures" class=""> LLE&lt;T&gt; {</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> End</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">indirect</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Node(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">, () -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LLE</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;, </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="m_1189542397825839138m_-5679191037068719472webkit-block-placeholder"></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> val() -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">? {</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">Node</span><span style="font-variant-ligatures:no-common-ligatures" class="">(v, </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class="">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class="">):</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> v</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">default</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">nil</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="m_1189542397825839138m_-5679191037068719472webkit-block-placeholder"></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> tail() -&gt; () -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">LLE</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt; {</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">Node</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class="">, tl, </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class="">):</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> tl</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">default</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal;color:rgb(209,47,27)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="">assert</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">false</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, </span><span style="font-variant-ligatures:no-common-ligatures" class="">"Can't call tail on empty list"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div style="font-size:11px;font-family:Menlo;margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">In my opinion this isn’t optimal (and can also create bigger problems, e.g. when implementing count). But enums in swift are purely functional and therefore functions without parameters always return the same value in an enum, so storing the result of a function call with no parameters could in some situations give a great performance boost.</div><div style="margin:0px;line-height:normal" class="">Has this issue already been discussed? If yes, what was the outcome? And if no, I would suggest an additional keyword “memoizing” for functions without parameters in enums. Or maybe someone has a better idea, which would fit better inside the swift universe?</div></span></div></div></div></blockquote><br class=""></div><div class=""><div class="">We've talked about "pure" functions (a prerequisite for memoization) a few times. Usually around the time we start talking about which definition of "pure" we want to use, someone will come by and say it's out of scope. IIRC, the last time it happened was after we started discussing Swift 4, so I'd guess it's still out of scope.</div><div class=""><br class=""></div><div class="">- Dave Sweeris&nbsp;</div></div>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div></div>
</div></blockquote></div><br class=""></div></div></body></html>