<div dir="ltr"><div><font face="arial, sans-serif"><br></font></div><font face="arial, sans-serif">Thank you all for the examples.</font><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Hehe real-world data structures are messy. Especially if dictated by systems utilities that don't care for functional programming.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">In the back of my mind is: do these idioms date from before there were pattern synonyms? Would matching to a pattern synonym give clearer code in the case branching?</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">(Would it be worth declaring a synonym for just one usage?)</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">There's only one of those examples where I feel expressing without the Pattern guard would be awkward. Tom's example 1., whose characteristics are:</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">* There's a long straggly sequence of matchers;</font></div><div><font face="arial, sans-serif">* With a particularly awkward branch in the middle, needing sub-analysis of a _component_ of the scrutinee, and only if such a component is present;</font></div><div><font face="arial, sans-serif">* If the sub-analysis fails to match, the logic must unnest itself and resume matching at the next branch of the straggle.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">The awkward branch (slightly reformatted) is</font></div><div><font face="arial, sans-serif"><br></font></div><div><pre style="white-space:pre-wrap;color:rgb(0,0,0)"><font face="arial, sans-serif">> (GET, [x]) | Just (path', mime) <- List.lookup x staticFiles</font></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)"><font face="arial, sans-serif">> -> Just (StaticFile mime path')
</font></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)"><font face="arial, sans-serif"><br></font></pre><pre style="white-space:pre-wrap;color:rgb(0,0,0)"><font face="arial, sans-serif">`staticFiles` is a module-wide variable, so matching is looking outside the scrutinee, therefore couldn't be expressed as a pattern synonym. The `lookup` might return a `Nothing`, so the inner pattern match could fail/this is doing more than a 'local binding' with `let`, which "always succeed" says the Language Report.</font></pre><br class="gmail-Apple-interchange-newline"></div></div>