PasteRack.org
Paste # 4629
2022-05-31 18:17:58

Fork as a new paste.

Paste viewed 1209 times.


Embed:

Classes and typed-racket

  1. #lang typed/racket
  2.  
  3. (define-type Hello-Class%
  4.   (Class
  5.    [say-hello (-> Void)]))
  6.  
  7. (: hello-class% Hello-Class%)
  8. (define hello-class%
  9.   (class object%
  10.     (super-new)
  11.     (define/public (say-hello)
  12.       (printf "Hello World!~%"))))
  13.  
  14. (: the-instance (U #f (Instance Hello-Class%)))
  15. (define the-instance #f)
  16.  
  17. (: say-hello (-> Void))
  18. (define (say-hello)
  19.   (unless the-instance
  20.     (set! the-instance (new hello-class%)))
  21.   (when (class? the-instance)
  22.     (send the-instance say-hello)))

=>