<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="">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 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 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;"> determinant() != </span><span class="" style="font-family: Menlo; color: rgb(39, 42, 216);">0</span>” part was <i class="">specifically</i> going to be a 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><blockquote type="cite" class=""><div class="">On Jan 13, 2016, at 09:56, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:<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=""> </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="">// ^~~ '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="">// 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="">// 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 </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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>