What is a pattern for a when‑guard?

21 views
Skip to first unread message

Yannick Duchêne

unread,
Jun 21, 2018, 1:03:01 PM6/21/18
to ats-lang-users
Hi there,

This question looks like a corner case, but it disturbs me to not be able to understand it. I tried but failed.

The clauses of a case expression expression can be guarded with a `when` part which follows the clause’s pattern. Ex.

        case m of
        | …
        | p when b => e
        | …

Where `p` is a pattern to be matched with `m`, `b` a boolean expression and `e` the resulting expression when that clause matches (ie. it passed pattern and guard).

In JSON data and in an ATS2 source file, I noticed a pattern can come instead of (or with?) the boolean expression in the `when` part. Exactly according to the file `pats_dynexp2.sats`, a `c2lau_gua` (the `when` part) is a list of `gm2at` which is made of a `d2exp` (a dynamic expression) and an optional `p2at` (a pattern).

It bugs me, since I failed to imagine what an example pattern can be and interpreted, and testing did not help neither.

Hongwei Xi

unread,
Jun 21, 2018, 3:07:42 PM6/21/18
to ats-lan...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/48c62449-7e79-489e-8702-d1843595fcec%40googlegroups.com.

Yannick Duchêne

unread,
Jun 21, 2018, 5:41:12 PM6/21/18
to ats-lang-users
Oh, thanks :;) . I missed it because it’s not in my local installation. I have an ats/doc directory, but this sub‑directory is not there. Will download it, it will be useful.


Le jeudi 21 juin 2018 21:07:42 UTC+2, gmhwxi a écrit :
On Thu, Jun 21, 2018 at 1:03 PM, 'Yannick Duchêne' via ats-lang-users <ats-lan...@googlegroups.com> wrote:
Hi there,

This question looks like a corner case, but it disturbs me to not be able to understand it. I tried but failed.

The clauses of a case expression expression can be guarded with a `when` part which follows the clause’s pattern. Ex.

        case m of
        | …
        | p when b => e
        | …

Where `p` is a pattern to be matched with `m`, `b` a boolean expression and `e` the resulting expression when that clause matches (ie. it passed pattern and guard).

In JSON data and in an ATS2 source file, I noticed a pattern can come instead of (or with?) the boolean expression in the `when` part. Exactly according to the file `pats_dynexp2.sats`, a `c2lau_gua` (the `when` part) is a list of `gm2at` which is made of a `d2exp` (a dynamic expression) and an optional `p2at` (a pattern).

It bugs me, since I failed to imagine what an example pattern can be and interpreted, and testing did not help neither.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages