/* Define a Prolog predicate replicate/3 which corresponds to
* the Haskell function of the same name, except that the numeric
* argument is expressed symbolically.
*
* For example, replicate(s(s(s(0))),a,[a,a,a]) should be satisfied.
*/
So far I've come to this solution:
replicate(0,_,[]).
replicate(X,Y,[Y|Z]) :- replicate(p(X),Y,Z).
but the problem is that the s(s(s(0))) is not getting reduced by the pred function. it results into p(p(p(s(s(s(0))))))
could you guys help me out?