Listing all the permutations of a given list

ATS is often considered a very verbose programming language.
This is largely due to the need for explicit construction of proofs
when more advanced typing features are involved.

If you use ATS as a ML-like language, then coding in ATS does
not have to be verbose. While ATS does not support HM-style of
type inference in ML, its support for overloading far exceeds ML.

For instance, the following piece of code lists all the permutations of
a given list:

//
extern
fun{a:t0p} Permute : list0(a) -> list0(list0(a))
implement{a}
Permute(xs) =
if isneqz(xs)
then concat(list0_tabulate(length(xs),lam(i)=>xs[i]*Permute(xs-i)))
else list0_sing(nil0)
//

So ATS can be quite concise as well :slight_smile:

Cheers!

My own experience says that shorter code is harder to write and
much harder to debug. I myself prefer writing code in A-normal form,
which makes it very convenient to insert debugging statements
(for use at either compile-time or run-time).

On Thursday, November 5, 2015 at 9:10:26 AM UTC-5, gmhwxi wrote own: