Created
June 21, 2012 21:59
-
-
Save takikawa/2968823 to your computer and use it in GitHub Desktop.
Cake pattern?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; ref: http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/ | |
(define-signature on-off-device^ | |
(on | |
off)) | |
(define-signature sensor-device^ | |
(is-coffee-present?)) | |
(define-unit heater@ | |
(import) | |
(export on-off-device^) | |
(define (on) (displayln "heater.on")) | |
(define (off) (displayln "heater.off"))) | |
(define-unit pot-sensor@ | |
(import) | |
(export sensor-device^) | |
(define (is-coffee-present?) #t)) | |
(define-signature warmer^ (trigger)) | |
(define-unit warmer@ | |
(import on-off-device^ sensor-device^) | |
(export warmer^) | |
(define (trigger) | |
(if (is-coffee-present?) | |
(on) | |
(off)))) | |
(define-values/invoke-unit/infer | |
(link warmer@ pot-sensor@ heater@)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment