#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])
;*****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
;*****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))))
Third, your version with structs can't work because you can't tell
what type a function expects -- that information is not there at
runtime.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BaE1h7tYT4nyRoAgUhVCWCNmJfvJ5V5QTzCcbwv_kvJhA%40mail.gmail.com.
On Mon, Nov 18, 2019 at 10:09 AM Sam Tobin-Hochstadt <sa...@cs.indiana.edu> wrote:
Third, your version with structs can't work because you can't tell
what type a function expects -- that information is not there at
runtime.If there is a contract assigned to a function, is it possible to get that function and analyze it?
It is possible to get the contracts of values, (see `value-contract`)
but Typed Racket doesn't know how to do that, and it would be
problematic anyway since the value isn't around until runtime, but TR
runs at compile time.
Sam
On Mon, Nov 18, 2019 at 12:24 PM David Storrs <david...@gmail.com> wrote:
>>> > To unsubscribe from this group and stop receiving emails from it, send an email to racket...@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.
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BaE1h7tYT4nyRoAgUhVCWCNmJfvJ5V5QTzCcbwv_kvJhA%40mail.gmail.com.
>
> --
> 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...@googlegroups.com.