Merging Logic and the Coinductive Selection Monad: Mixing Machine Learning Into Logical Search
摘要
We present a monadic library in Scala that extends the capabilities of logical programming by integrating machine learning feedback into declarative search. Built upon the dotty-cps-async implementation of the Logic monad, our approach introduces result reordering mechanisms for logical streaming operations. This enhancement allows more flexible and efficient evaluation strategies in logical computations. A key contribution of our work is the extension of the LogicalMonad interface with facilities for directed search—enabling the scoring of results during backtracking. This scoring mechanism serves as a bridge between logic-based search and machine learning models, which typically output evaluation metrics rather than deterministic answers. By combining this scoring with a monadic unification framework, we develop a universal and composable architecture for declarative programming in Scala. Our framework enables developers to guide logical search processes based on external or learned preferences, making it well-suited for applications that require probabilistic reasoning or adaptive feedback. Moreover, the modular design of the system allows for the gradual integration of machine learning components into existing traditional software systems without full rewrites. This approach opens new possibilities for hybrid systems that leverage both symbolic reasoning and statistical learning within a unified and expressive programming paradigm.