In typed racket, how would I add type annotations for this:
(define (register-fs-events)
(define paths (find-files filter-actual-sources))
(for/list ([f (in-list paths)]
[i (in-naturals)])
(filesystem-change-evt f)))
> Type Checker: Error in macro expansion — insufficient type information to typecheck. please add more type annotations > in: (for/list ((f (in-list paths)) (i (in-naturals))) (filesystem-change-evt f))
I have tried:
(define (register-fs-events)
(: paths (Listof Path))
(define paths (find-files filter-actual-sources))
(for/list ([f (in-list paths)]
[i (in-naturals)])
(filesystem-change-evt f)))
Which gives the same results.
(define (register-fs-events)
(: paths (Listof Path))
(define paths (find-files filter-actual-sources))
(: f Path)
(for/list ([f (in-list paths)]
[i (in-naturals)])
(filesystem-change-evt f)))
Which gives me
> Type Checker: Declaration for f' provided, but
f’ has no definition
(define (register-fs-events)
(: paths (Listof Path))
(define paths (find-files filter-actual-sources))
(for/list ([[f : Path] (in-list paths)]
[[i : Natural] (in-naturals)])
(filesystem-change-evt f)))
Which gives me
> let-values: duplicate binding name > at: : > in: (let-values (((f : Path all-cont?/pos) (let-values (((f : Path) (pos->vals pos))) (values f : Path (and all-cont? (lambda (pos) (all-cont? pos f : Path)))))) ((pos) (if pos-pre-inc (pos-pre-inc pos) pos)) ((i : Natural all-cont?/pos) (let-values (((i : …
So now I’m lost … how can I type annotate this properly?
it’s the syntax for type annotation for for[/*]
Thanks!
Now I have
(define (register-fs-events)
(: paths (Listof Path))
(define paths (find-files filter-actual-sources))
(for/list ([f : Path (in-list paths)])
(filesystem-change-evt f)))
And I’m back on
> Type Checker: Error in macro expansion — insufficient type information to typecheck. please add more type annotations > in: (for/list ((f : Path (in-list paths))) (filesystem-change-evt f))
made me realize I had no use for the [i (in-naturals)]
I’m not sure what more I can annotate for that for/list
macro
I just got this:
I don’t do typed racket, but I can’t imagine annotating f
would be of any help since you’ve already annotated paths
.
> filesystem-change-evt
- : (All (a)
(case->
(-> Path-String (Rec x (Evtof x)))
(-> Path-String (-> a) (U (Rec x (Evtof x)) a))))
#<procedure:filesystem-change-evt>
(define (register-fs-events)
(define paths
...)
(for/list : (Listof (U (Evtof Path)
(Rec x (Evtof x))))
([f (in-list paths)]
[i (in-naturals)])
(filesystem-change-evt f)))
instead of annotating the type of the result of for/list
, you could as well annotate the type of register-fs-events
yeah, it was the full list annotation missing, many thanks!
looks like this works: (: register-fs-events (-> (Listof (U (Evtof Path)
(Rec x (Evtof x))))))
(define (register-fs-events)
(define paths
...)
(for/list ([f (in-list paths)]
[i (in-naturals)])
(filesystem-change-evt f)))
And indeed just annotating the function removes the need to annotate anything inside of it