<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="">Am 13.01.2016 um 20:37 schrieb <a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a>:</div><br class="Apple-interchange-newline"><div 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="">Matt, funny you should use that example… We might be trying to work on the same sorts of problem :-)<div class=""><br class=""></div><div class="">Thorsten, I don’t see why it wouldn’t work for any immutable&nbsp;matrix (literal or otherwise), or even mutable matrices <i class="">if</i> assignment operations were allowed to fail*, or Swift supported class clusters (such as NSNumber, appropriately enough) it could just change its “private” type behind the scenes if needs be (at least I think I remember reading that NSNumber does that).</div></div></div></blockquote><div><br class=""></div>Ah, ok, I see what you mean. The question is when should determinant() be calculated? If Matrix is immutable it can be done just after initialization and be memoized. Or lazy at the first time the dynamic type is needed (and then memoized). This would add a lot of complication, though.</div><div><br class=""></div><div>A very nice research language called Cecil (by Craig Chambers from the University of Washington, later replaced by the similar language Diesel) once had a feature like that. They called it "Predicate Objects“ (see&nbsp;<a href="http://www.cs.washington.edu/research/projects/cecil/www/research.html#cecil" class="">http://www.cs.washington.edu/research/projects/cecil/www/research.html#cecil</a>).&nbsp;</div><div>Cecil had many very nice features like multimethods with multiple dispatch implemented in a quite nice way.</div><div><br class=""></div><div>-Thorsten</div><div><span class="Apple-tab-span" style="white-space:pre">        </span><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><div class="">[At this point I remembered that Matt was thinking the “<span class="" style="font-family: Menlo; color: rgb(187, 44, 162);">where</span><span class="" style="color: rgb(0, 132, 0); font-family: Menlo;">&nbsp;determinant() !=&nbsp;</span><span class="" style="font-family: Menlo; color: rgb(39, 42, 216);">0</span>” part was <i class="">specifically</i> going to be a&nbsp;compile-time check, and pretty much everything I’d written was coming from the run-time point of view…] Ok, so… what if “where” clauses in the “inheritance" section forced all the initializers to be failable, and there was an implicit “if !(where clause) { return nil }” inserted at the end of every initializer? It’d cut down on boilerplate code, and it’d tell whomever was looking at the public interface two things: 1) That all the initializers had “universal precondition”, and 2) exactly what that universal precondition is. I mean if you were using a matrix library and only had what they exposed to go on, which would be more useful to you, having an API note that says, “blah blah square matrix blah nonzero determinant blah blah”, or being able to examine the actual bit of code that will determine if your data can pass the “universal” validation check?</div></div><div class=""><br class=""></div><div class="">*Yes, I know you can use will/didSet to roll back the changes if the new value fails some validation check. I can’t figure out a way to get those to throw errors, though, nor is there currently a way to have subscript() throw an error (somebody’s already filed a radar about that). Since there’s no way to alert the programmer that the assignment they just performed might not stick, this seems like a colossally bad idea (for general code, anyway… obviously if it works in your specific situation, then go for it).</div><div class=""><br class=""><div class="">
- Dave Sweeris

</div><div class=""><br class="webkit-block-placeholder"></div><div class="">(At what point does something need to get split off into its own thread? Because after typing this all up, I’m not sure it’s particularly related to what we’ve been talking about here.)</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 13, 2016, at 09:56, Thorsten Seitz 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=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><div class=""><br class=""></div><div class="">Am 12.01.2016 um 23:49 schrieb Matt Whiteside via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class=""><br class=""></div><blockquote type="cite" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span><span style="" class=""> InvertibleMatrix: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SquareMatrix</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span><span style="" class=""> determinant() != </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="" class="">&nbsp;</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~ 'restriction’ clause, i.e., not inheritance;</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(0, 132, 0);" class="">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; determinant() is executed at compile time,</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(0, 132, 0);" class="">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; since `entries` is a constexpr</span></div></blockquote><br class=""><div class="">Wouldn't that only work for literal matrices?</div><div class=""><br class=""></div><div class="">-Thorsten&nbsp;</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=mnFI6pg-2FTCMHnIXafbniMQOkvAOxgYUwbalcxNWA5RcLd3iO-2FP2D3TDMpSTm3e0bsU4Zx-2Fn4ltBeIwBvKM-2FVe9NBdQkGiGMbABzQ2jo-2B8q6t5jSq8nOSjnJZ6Ss-2BfG7h1UVJ-2B-2BhclkuvROm3ZCfw-2BiGAkCKcQ5xH5-2BetrU0zJTEWfn0k7-2FarsqGHuPmSaEXIYNxhQz8xrXHMBpt-2BSXNkfPslztTXTdBUJPkiF9Twpr8-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>