implementing templates as programs