Direct use of if-then-else with function type cause "Program error"