# generic way to convert imperative if-then-else statements into functional style?

In this question, I asked about a reference for translating imperative code to functional code. I want to ask a more specific question here.

How, in general, do we translate into functional style, a statement of the form:

if (cond) then
do x;
else
do y;


I know that functional languages have if-then-else statements but the expressions are only allowed to be pure. Is there a general way of doing this translation?

• Recursively, translate the do x and do y first. Mar 3 '20 at 2:30

As was mentioned in comments to the other question, any imperative program with side-effects can be trivially transformed into a pure program by simply lifting it into the IO monad, for example.