# Why doesn't Compile work on Permutations function with second args?

Here is a narrowed-down example, the first case works, but the second one refuses to use the compiled version:

 Compile[{}, Permutations[{1, 2, 3}]][]

Compile[{}, Permutations[{1, 2, 3}, {2}]][]


Full code:

Compile[{},
Module[{c, d, e, g, l, m, o, t, w, A = 10^Range[5, 0, -1]},
Do[{c, d, e, g, l, m, o, t, w} = x;
If[{w, w, w, d, o, t}.A - {g, o, o, g, l, e}.A == {d, o, t, c, o,
m}.A, Print@x], {x, Permutations[Range[0, 9], {9}]}]]
][]

-

In fact, Compile really doesn't work with either of them, a fact revealed by the appearance of the MainEvaluate in the output of CompilePrint.

Needs["CompiledFunctionTools"]
f1 = Compile[{}, Permutations[{1, 2, 3}]];
f2 = Compile[{}, Permutations[{1, 2, 3}, {2}]];
CompilePrint[f1]

(*
No argument
2 Tensor registers
Underflow checking off
Overflow checking off
Integer overflow checking on
RuntimeAttributes -> {}

T(I1)0 = {1, 2, 3}
Result = T(I2)1

1   T(I2)1 = MainEvaluate[ Hold[Permutations][ T(I1)0]]
2   Return
*)


We'd like it to look more like the following, in which MainEvaluate does not appear:

f3 = Compile[{x}, 2/3 - 4 Cos[x^2 + 1]^3,
CompilationTarget -> "C"];
CompilePrint[f3]

(* Out:
1 argument
4 Integer registers
4 Real registers
Underflow checking off
Overflow checking off
Integer overflow checking on
RuntimeAttributes -> {}

R0 = A1
I3 = 1
I0 = 2
I2 = 4
I1 = 3
Result = R1

1   R1 = I1
2   R2 = Reciprocal[ R1]
3   R1 = I0
4   R1 = R1 * R2
5   R2 = Square[ R0]
6   R3 = I3
7   R2 = R2 + R3
8   R3 = Cos[ R2]
9   R2 = Power[ R3, I1]
10  R3 = I2
11  R3 = R3 * R2
12  R2 = - R3
13  R1 = R1 + R2
14  Return
*)
`
-
Related: The two "Edit" sections here mathematica.stackexchange.com/a/1101/5 – R. M. Feb 26 '13 at 14:35