14 Units
top
up

14.5Whole-module Signatures and UnitsπŸ”— i

In programs that use units, modules like "toy-factory-sig.rkt" and "simple-factory-unit.rkt" are common. The racket/signature and racket/unit module names can be used as languages to avoid much of the boilerplate module, signature, and unit declaration text.

For example, "toy-factory-sig.rkt" can be written as

build-toys;(integer? -> (listof toy?))
repaint;(toy? symbol? -> toy?)
toy?;(any/c -> boolean?)
toy-color;(toy? -> symbol?)

The signature toy-factory^ is automatically provided from the module, inferred from the filename "toy-factory-sig.rkt" by replacing the "-sig.rkt" suffix with ^.

Similarly, "simple-factory-unit.rkt" module can be written

(require "toy-factory-sig.rkt")
(import )
(export toy-factory^)
(printf "Factory started.\n")
(struct toy(color)#:transparent)
(define (build-toysn)
(for/list ([i(in-range n)])
(toy'blue)))
(define (repainttcol)
(toycol))

The unit simple-factory@ is automatically provided from the module, inferred from the filename "simple-factory-unit.rkt" by replacing the "-unit.rkt" suffix with @.

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /