Hi,

I'm trying to go from a small racket program that uses classes to a typed 
racket version of the program, but I can't find a combination of types that 
works. (The untyped version works as intended.)

Specifically, if I have a recipe% class, and an amount-mixin and unit-mixin , 
and each of these 3 have 1-argument init specifiers, how do I add types to 
both mixins such that (amount-mixin (unit-mixin recipe%)) works? (edited) 

The untyped version:

    #lang racket/base
     
    (require racket/class)
     
     
    (define recipe%
      (class object%
        (init name #;steps )
        (super-new)
        (define _name name)
        ;(define _steps steps)
        ;(define/public (get-steps) _steps)
        (define/public (get-name) _name)))
     
     
    (define (amount-mixin %)
      (class %
        (init amount)
        (define _amount amount)
        (super-new)
        (inherit get-name)
        (define/public (get-amount) _amount)))
     
     
    (define (unit-mixin %)
      (class %
        (init unit)
        (define _unit unit)
        (super-new)
        (inherit get-name)
        (define/public (get-unit) _unit)))
     
     
    (unit-mixin (amount-mixin recipe%))


And the typed version (that raises an error):

#lang typed/racket/base

(require typed/racket/class)


(define-type recipe<%>
  (Class (init [name String])
         (get-name (-> String))))
(: recipe% recipe<%>)
(define recipe%
  (class object%
    (init [name : String])
    (super-new)
    (: _name String)
    (define _name name)
    (define/public (get-name) _name)))


(: amount-mixin (->  recipe<%>
                     (Class #:implements recipe<%>
                            (init [amount Number]
                                  [name String])
                            (get-amount (-> Number)))))
(define (amount-mixin %)
  (class %
    (init [amount : Number])
    (: _amount Number)
    (define _amount amount)
    (super-new)
    (inherit get-name)
    (define/public (get-amount) _amount)))


(: unit-mixin (-> recipe<%> (Class #:implements recipe<%>
                                   (init [unit String]
                                         [name String])
                                   (get-unit (-> String)))))
(define (unit-mixin %)
  (class %
    (init [unit : String])
    (: _unit String)
    (define _unit unit)
    (super-new)
    (inherit get-name)
    (define/public (get-unit) _unit)))


(unit-mixin (amount-mixin recipe%))


Any advice on how to make this work? Or whether to simply not do this in 
typed racket?

Regards,
Hashim.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/59b0b8f4-beb6-4bf9-89e4-82e3fb74e148n%40googlegroups.com.

Reply via email to