<div dir="ltr">Good question! The trick is that `match` is passed an (n-ary) Haskell function on embedded terms (in the example hidden as a lambda-case) which it can continually re-apply, forcing every case alternative to succeed in turn so that we can explore the right-hand-side of each equation. This is necessary because we have staged compilation; the Haskell case statement is being resolved at an earlier stage (and possibly on a different device) than when we find out which branch actually succeeds. I think it's an interesting use case for explicitly bi-directional pattern synonyms which I haven't seen before.<div><br></div><div>-T<br><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 1 Sep 2020 at 15:39, Emil Axelsson <<a href="mailto:78emil@gmail.com">78emil@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Nice! How is that done?<br>
    </p>
    <pre cols="72">/ Emil</pre>
    <div>Den 2020-09-01 kl. 13:50, skrev Trevor
      McDonell:<br>
    </div>
    <blockquote type="cite">
      <h3>Embedded pattern
        matching</h3>
      <p>This
        release also introduces support for <em style="box-sizing:border-box">embedded pattern matching</em> via
        the new <code>match</code> operator,
        which allows us to reuse Haskell's case syntax in embedded code:</p>
      <div>
        <pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:11.899999618530273px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:6px;border-top-right-radius:6px;border-bottom-right-radius:6px;border-bottom-left-radius:6px;word-break:normal"><span style="box-sizing:border-box;color:rgb(111,66,193)">intersect</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">::</span> <span style="box-sizing:border-box;color:rgb(111,66,193)">Exp</span> <span style="box-sizing:border-box;color:rgb(111,66,193)">Ray</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span style="box-sizing:border-box;color:rgb(111,66,193)">Exp</span> <span style="box-sizing:border-box;color:rgb(111,66,193)">Object</span> <span style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span style="box-sizing:border-box;color:rgb(111,66,193)">Exp</span> <span style="box-sizing:border-box;color:rgb(111,66,193)"><span style="box-sizing:border-box;color:rgb(0,92,197)">Bool</span></span>
intersect ray <span style="box-sizing:border-box;color:rgb(215,58,73)">=</span> match <span style="box-sizing:border-box;color:rgb(215,58,73)">\</span><span style="box-sizing:border-box;color:rgb(215,58,73)">case</span>
  <span style="box-sizing:border-box;color:rgb(34,134,58)">Sphere_</span> c r     <span style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span style="box-sizing:border-box;color:rgb(215,58,73)">...</span>
  <span style="box-sizing:border-box;color:rgb(34,134,58)">Triangle_</span> a b c <span style="box-sizing:border-box;color:rgb(215,58,73)">-></span> <span style="box-sizing:border-box;color:rgb(215,58,73)">...</span></pre>
      </div>
    </blockquote>
  </div>

</blockquote></div>