; Copyright 2005 Brian Alliet (define (main args) (unsafe-perform-io (do io: (put-str-ln "Hello, World") (put-str-ln (show (e maybe: '(1 2 5 10) 12))) (put-str-ln (show (e list: '(1 2 5 10) 12))) (put-str-ln (show (e maybe: '(2 5 10) 11))) (put-str-ln (show (e list: '(2 5 10) 11))) (cs <- (read-file "monad.scm")) (write-file "dump.txt" cs) (io:return 0) ))) ; This function is parameterized over any MonadPlus instance ; It returns a combinaion of numbers in xs whose sum is t ; Running it under the Maybe monad yields 1 or 0 results ; Running it under the List monad yields all results (define (e d: xs t) (match xs ((cons x xs) (cond ((= x t) (return d: (list x))) ((< x t) (msum d: (list ((lift-m d: (left-section cons x)) (e d: xs (- t x))) ((lift-m d: (left-section cons (- x))) (e d: xs (+ t x))) (e d: xs t)))) (else (mzero d:)))) (_ (mzero d:))))