You need to inject the body of your function definition(s) into the Compile call without evaluating it. One possibility is (I had to change your Module a bit to correct a type error)
foo[p_] := 0.7 Exp[-p^2]
f[a_, n_] := Module[{s = 0.0, p = a, i},
For[i = 0, i < n, i++, s += foo[p]; p *= a;]; s]
cf = ReleaseHold[Hold[Compile[{{a, _Real}, {n, _Integer}}, f[a, n]]]
/. DownValues[f] /. DownValues[foo]]
More explanation
First of all you need to understand that when you make a function definintion, Mathematica stores a replacement rule. There are different kinds of such rules and the most important ones are DownValues and OwnValues. OwnValues are used when you make assignments like x=1 or x:=1. DownValues are for function definitions. Let take a look at the rules of foo
DownValues[foo]
(* {HoldPattern[foo[p_]] :> 0.7 Exp[-p^2]} *)
Very sloppy speaking, when you make any calculation in Mathematica then it looks at your code and checks what rules are connected with a symbol. Then it uses these rules and makes the replacement, if the pattern matches.
In your case, the problem with your Compile call is that
Compile has the attribute HoldAll which prevents that f[a,n] is replaced with its definition.
- If you force the evaluation of the expression
f[a,n] using Evaluate then it does too much, because it doesn't only insert the definition body of f (the Module part) but it evaluates it right away. This is not good because at this point, you don't have numeric values for a and n and therefore, the For loop doesn't do anything at all.
At this point, it is clear what you want: You have made a definition for f[a,n], how can you get the fully expanded function body? Two ingredients: First, you use the definition rules (DownValues) by yourself and second, you prevent the evaluation using Hold. There you go..
Hold[f[a, n]] /. DownValues[f]
(* Hold[Module[{s$ = 0., p$ = a, i$},
For[i$ = 0, i$ < n, i$++, s$ += foo[p$]; p$ *= a;]; s$]]
*)
As you see we are not finished, because the definition of foo was not expanded, but this is not a problem, because we can do it the same way. All this combined with Compile gives the above solution.