On 2/19/20, unlimitedscolobb <
unlimite...@gmail.com> wrote:
>
> [....]
>
> ;Type Checker: Type a could not be converted to a contract because it
> contains free variables.
> ; in: a
>
> Does this mean that I can never cast to types containing type variables?
Yes
> My original problem comes from playing around with eval, which returns
> AnyValues. Ideally, I would like to be able to retrieve the first returned
>
> value (done), and then convert it to a type variable bound by one of the
> arguments:
>
> (: my-super-func (All (a) (-> (Type1 a) a)))
> (define (my-super-func arg)
> ...
> (get-first-value (eval some-stuff))) ; how to cast to a ?
You can ask the caller to supply a cast function that turns an Any to an A.
But depending on what you want to cast to, occurrence typing may be
more convenient. For example:
#lang typed/racket
(: my-super-func (All (a) (-> (-> Any) (-> Any Boolean : #:+ a) a)))
(define (my-super-func get-v check-v)
(assert (get-v) check-v))
(ann (my-super-func (lambda () 42) exact-integer?) Integer);
;; 42
(ann (my-super-func (lambda () '(A)) (lambda (x) (and (list? x)
(andmap symbol? x)))) (Listof Symbol))
;; '(A)