khepin
2018-8-8 19:30:57

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, butf’ 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?



shu--hung
2018-8-8 19:36:36

it’s the syntax for type annotation for for[/*]


khepin
2018-8-8 19:40:14

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))


khepin
2018-8-8 19:40:35

made me realize I had no use for the [i (in-naturals)]


khepin
2018-8-8 19:41:27

I’m not sure what more I can annotate for that for/list macro


shu--hung
2018-8-8 19:41:52

I just got this:


zenspider
2018-8-8 19:41:53

I don’t do typed racket, but I can’t imagine annotating f would be of any help since you’ve already annotated paths.


shu--hung
2018-8-8 19:42:14
> 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>

shu--hung
2018-8-8 19:42:33
(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)))

shu--hung
2018-8-8 19:44:02

instead of annotating the type of the result of for/list, you could as well annotate the type of register-fs-events


khepin
2018-8-8 19:44:23

yeah, it was the full list annotation missing, many thanks!


shu--hung
2018-8-8 19:44:49

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)))


khepin
2018-8-8 19:46:52

And indeed just annotating the function removes the need to annotate anything inside of it