In this paper we describe a didactic approach that seeks to include the stages of programming in the process of problem solving in mathematics and physics. Secondary education teachers were introduced to the strategy in a teacher training course that emphasises the importance of discrete mathematics and logic as the foundations of Computer Science concepts. A functional programming language -named MateFun- was used to explore the goals of the didactic strategy. The language can animate figures, a feature useful for physics learning experiences in the sense that visual representations of solutions to problems can be programmed. The didactic approach introduces programming into the learning experience beyond the instrumental use of technology and contributes to a natural introduction of Computer Science in other subjects. The paper contains examples and conclusions.