ifcase-expressions

41 views
Skip to first unread message

gmhwxi

unread,
May 22, 2016, 12:24:21 AM5/22/16
to ats-lang-users

ATS2 now supports ifcase-expressions, which are similar to
the if-expressions in Erlang. Here is an example:

//
fun
acker
{m,n:nat}
.<m,n>.
(
  m
: int(m)
, n: int(n)
) : intGte(0) =
(
ifcase
| m = 0 => n + 1
| n = 0 => acker(m-1, 1)
| _(*else*) => acker(m-1, acker(m, n-1))
// end of [ifcase]
)
//

Note that the ifcase-expression in the above code is equivalent
to the following one:

if m=0 then n+1 else if n=0 then acker(m-1, 1) else acker(m-1, acker(m, n-1))

gmhwxi

unread,
May 22, 2016, 12:29:19 AM5/22/16
to ats-lang-users

Like an if-expression, an ifcase-expression can also be
annotated with a state type. Please see an example by visiting
the following link:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/TESTATS/ifcase.dats

Steinway Wu

unread,
May 23, 2016, 10:31:20 AM5/23/16
to ats-lang-users
This is cool!


On Sunday, May 22, 2016 at 12:24:21 AM UTC-4, gmhwxi wrote:
Reply all
Reply to author
Forward
0 new messages