<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 Dec 22, 2016, at 7:43 PM, Robert Widmann <<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>> wrote:</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=""><div class="">Do you think there’s room for a more general <a href="https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms" class="">Pattern Synonyms-like</a> feature that could extend this to things that look tuple-y? We had a short conversation on Twitter 'round about the release of Swift 1.2 about Swiftz’s <a href="https://github.com/typelift/Swiftz/blob/master/Sources/HList.swift#L185" class="">HList</a> implementation and my desire to be able to destructure them into tuples for native pattern matching.</div></div></div></blockquote><br class=""></div><div>My personal favorite design for user-extensible pattern syntax is F#'s "active pattern" feature, which lets you declare a set of mutual exclusive, total or partial conditions along with a function body that computes which condition holds. For the specific case of container patterns, though, I feel like it's worth keeping a close association with Collection semantics, so that:</div><div><br class=""></div><div>- [] matches when the incoming collection's startIndex == endIndex,</div><div>- [<pattern>, <pattern-list>] fails if startIndex == endIndex, or else matches collection[startIndex] against <pattern> and recursively matches collection[startIndex.advancedBy(1)..<endIndex] against [<pattern-list>]</div><div>- [<pattern>...] matches the remaining collection against <pattern></div><div><br class=""></div><div class="">-Joe</div></body></html>