[Haskell-cafe] [ANN] Accelerate v1.3

Trevor McDonell trevor.mcdonell at gmail.com
Tue Sep 1 15:12:31 UTC 2020


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.

-T


On Tue, 1 Sep 2020 at 15:39, Emil Axelsson <78emil at gmail.com> wrote:

> Nice! How is that done?
>
> / Emil
>
> Den 2020-09-01 kl. 13:50, skrev Trevor McDonell:
>
> Embedded pattern matching
>
> This release also introduces support for *embedded pattern matching* via
> the new match operator, which allows us to reuse Haskell's case syntax in
> embedded code:
>
> intersect :: Exp Ray -> Exp Object -> Exp Bool
> intersect ray = match \case
>   Sphere_ c r     -> ...
>   Triangle_ a b c -> ...
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200901/de103ccc/attachment.html>


More information about the Haskell-Cafe mailing list