Hello,

I was trying to type some polymorphic classes but I got stuck early on 
making a polymorphic subclass

#lang typed/racket/base

;*****1*****
(require typed/racket/class)

(define-type (C-class A)(Class [init-field [x A]]))

(define C1% 
 (class object%
 #:∀ (A)
 (init-field [x : A])
 (super-new)))

(define C2%
 (class (inst C1% A)
 #:∀ (A)
 (super-new)))

(new (inst C2% Integer) [x 4])

C1% is recognised as a C-class, but explicitly calling C1% a C-class 
(omitting the #:forall (A) ) doesn't work
In the next step I don't seem to find the right way to make C2% a 
polymorphic subclass of C1%



Having failed that I went with structures. This I got mostly working, but I 
would like to have some niceties.
One was to parameterize a structure, but this lead to a problem of not 
being able to check some
types at runtime. I thought I got close, but I stranded on getting fields 
of structures without knowing the instantiation type
;*****2*****
(struct (A) S ([f1 : (-> A A A)]
               [f2 : (-> A Boolean : A)]))

(: S-of-type? (-> (-> Any Boolean : A) Any Boolean
                  : #:+ (implies #t (S A))
                    #:- (implies #f (! (S A)))))
(define (S-of-type? fct A)
  (and (S? A) (eq? fct (S-f2 A))))
;                      ^ how can I acces a field of this polymorfic struct



And another thing I tried but failed to get working is to sub-type a 
structure based
on a narrower type for one of the fields.
;*****3*****
(struct (A) B ([f1 : (Vectorof A)]
               [f2 : Integer])
  #:transparent)

(: B1? (All (A) (-> (B A) Boolean)))
(define (B1? b)(= (B-f2 b) 1))
(define b (B (vector 3) 1))
(assert b B1?)
b
(define-type B1 B1?)
;(define-new-subtype B1 B1?)
;(define-type B1 (All (A)(Struct (B (Vectorof A) 1))))


Are any of these things doable? Or are there better ways to tackle this 
problems?


What I got working is in 
https://github.com/bdeket/polynomials/blob/alg-dic-pol/polynomials/math/private/polynomial/poly-struct.rkt
 
(WIP)

Kind regards,
Bert

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/3c4bcedd-5677-4972-97a3-04e33ca30816%40googlegroups.com.

Reply via email to