Partial-evaluation of Monads in Scheme - A New Hope?
Sun 21 May 2006 13:28 BST
The other day, I noted that my generic-monad-in-Scheme implementation suffered from the flaw of not being able to type-check monad assemblies before any actions had been executed, and that in general such ahead-of-time checking is not possible without abstract interpretation of some kind, because the functional code in the right-hand-side of the bind operator can decide which action to splice into the monad next:
(define (goes-wrong) (run-io (mlet* ((val mread)) (if val ;; if the user entered #f, we break, otherwise we're fine (mlet* ((_ (mdisplay "Was true\n"))) (return 'apples)) 'bananas)))) ;; Note: missing "(return ...)"!
Perhaps a partial-evaluator can play the part of a Haskell-type-system-like abstract interpretation well enough to drive the type-safety checks through the code at PE time (loosely equivalent to static-analysis time) for most cases (leaving the remaining cases for runtime-detection, as in the present implementation, and perhaps warning the user)? In order to find out, my next experiment in this direction will be marrying the monad code to the partial-evaluator I implemented some months ago.