Like natural language, music can be described as being composed of various parts, which combine together to form a set-theoretic or logical entity. The conceptualized parts are more basic than the music seen on a page; they are the musical objects subject to music-theoretic analysis, and can be described using the language of functional programming and lambda calculus. This paper introduces the types of musical objects seen in tonal and modern music, as well as the combinators that allow them to combine to create other musical objects. We propose a method for automatically generating melodies by searching for combinations of musical objects which together produce a valid program corresponding to a melody or set of melodies.