<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 21, 2017, at 8:57 PM, Michel Fortin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">(this was accidentally sent off-list, reposting here a day later)<br class=""></div></div></blockquote><div><br class=""></div>And this was my reply.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">Le 20 févr. 2017 à 12:17, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; a écrit :<br class=""><br class=""><blockquote type="cite" class="">e) Generic Containers:<br class="">Generic containers that impose requirements on their elements will pose some additional problems, for instance: `Set.insert` needs to call `hashValue` and `==` on its elements, making the purity of `Set.insert` constrained by the purity of those functions. Without a way to express this kind of conditional purity, `Set` and `Dictionary` cannot be pure.<br class=""></blockquote><br class="">Could we use a mechanism similar to `rethrows` to address this kind of transitive purity? &nbsp;We have already discussed something along those lines for handling functions passed as arguments. &nbsp;Maybe that mechanism could be designed to handle this use case as well.<br class=""></blockquote><br class="">Similar, yes. But more complicated too. In pseudo code, this is what you'd have to express for `Set.insert`:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>pure(where: Element.hashValue is pure, Element.== is pure)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func insert(_ element: Element) { ... }<br class=""><br class="">Then the compiler can enforce that `insert` only does things that are allowed in a pure function, but can ignore the purity of Element.hashValue and Element.== because the caller will check for that that.<br class=""></div></div></blockquote><div><br class=""></div><div><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>Yep, that’s the kind of thing I had in mind.<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote><font color="#00afcd" class=""><br class=""></font><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>I can imagine being this explicit could get pretty cumbersome though. &nbsp;I wonder if there is a way to streamline this. &nbsp;For example, in this case if we could just talk about `Element`’s conformance to `Hashable` and we could talk about a `pure` conformance (all requirements are met with pure implementations) then we could just say something like this:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote><font color="#00afcd" class=""><br class=""></font><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>pure(Element.Hashable)<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>func insert(_ element: Element) { ... }<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote><font color="#00afcd" class=""><br class=""></font><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>Note: I also removed some redundancies - we could just say that the parameters are a list of things the purity of which `insert`’s purity depends.<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote><font color="#00afcd" class=""><br class=""></font><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>For function arguments it would look something like this:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote><font color="#00afcd" class=""><br class=""></font><blockquote type="cite" class=""><blockquote type="cite" class=""></blockquote></blockquote>pure(transform)<br class="">func map&lt;T&gt;(transform: Element -&gt; T)</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">-- <br class="">Michel Fortin<br class=""><a href="https://michelf.ca" class="">https://michelf.ca</a><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></body></html>