Axel, 

I tend to organize modules around classes so that I avoid the "Asumu pitfall": 

#lang typed/racket

(define-type Polynome% 
 (Class
  [init-field [a [Vectorof Real]]]
  [value (-> Real Real)]
  [derive (-> Polynome)]))

(define-type Polynome (Instance Polynome%))

#;
(type-out
 [create-polynome (-> [Vectorof Real] Polynome)])
;; where is it? 

(provide
 create-polynome)

(: create-polynome (-> [Vectorof Real] Polynome))
(define (create-polynome a0)
  (new polynome% [a a0]))

;; represent the polynomial p(x) = Σ a(i) * x^i
(: polynome% Polynome%)
(define polynome%
  (class object%
    (init-field
     ;; [Vectorof Real]
     a)
    (super-new)

    ;; Real -> Real 
    (define/public (value x)
      (* (vector-ref a 0) x))

    ;; -> Polynome
    (define/public (derive)
      (create-polynome a)
      #;
      (new this% [a a]))))

(: polynome Polynome)
(define polynome (new polynome% [a #(1 2 3)]))

(send polynome value 1)
(send (send polynome derive) value 1)


Warning: functionality intentionally wrong. 

I started from this untyped version: 

#lang racket

(provide
 ;; type Polynome =
 #;
 (Class
  [field a [Vectorof Real]]
  [value (-> Real Real)]
  [derive (-> Polynome)])

 ;; [Vectorof Real] -> Polynome
 create-polynome)

(define (create-polynome a)
  (new polynome [a a]))

;; represent the polynomial p(x) = Σ a(i) * x^i
(define polynome%
  (class object%
    (init-field
     ;; [Vectorof Real]
     a)
    (super-new)

    ;; Real -> Real 
    (define/public (value x)
      (* (vector-ref a 0) x))

    ;; -> Polynome
    (define/public (derive)
      (create-polynome a)
      #;
      (new this% [a a]))))


(define polynome (new polynome% [a #(1 2 3)]))

(send polynome value 1)
(send (send polynome derive) value 1)

;; You see how adding types clarified my thoughts. -- Matthias

-- 
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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to