# No static type checking of 'in-list' form used in 'for'?

**URL:** <https://racket.discourse.group/t/no-static-type-checking-of-in-list-form-used-in-for/1548>\
**Category:** Questions & Answers\
**Created:** [December 10, 2022, 9:08pm UTC](https://racket.discourse.group/t/no-static-type-checking-of-in-list-form-used-in-for/1548 "2022-12-10T21:08:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [December 10, 2022, 9:08pm UTC](https://racket.discourse.group/t/no-static-type-checking-of-in-list-form-used-in-for/1548/1 "2022-12-10T21:08:04Z")

</div>

I was surprised by this program's type-checking behavior:

```scheme
#lang typed/racket

(define definitely-not-a-list string-length)

;; this doesn't type-check:
#;(in-list definitely-not-a-list)

;; and neither does this
#;(for/list : (Listof Real)
  ([i (in-range 4 10)]
   [b definitely-not-a-list])
  i)

;; but this does!
(for/list : (Listof Real)
  ([i (in-range 4 10)]
   [b (in-list definitely-not-a-list)])
  i)

```

After thinking about it some more, I'm guessing that the 'in-list' is expanded in the context of the 'for' into something that TR has a hard time analyzing, so it just inserts a contract check. I'm guessing that the expansion of `for` could be enriched to allow TR to check this, but ... maybe it's not worth it?

If my suppositions here are right, it gives me a moment's pause, because it suggests weirdly that I should avoid using `in-list` in TR code to get better checking.

Am I missing something obvious?

---

<div class="post-metadata">

**Author:** ![gus-massa](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/gus-massa/32/507_2.png) [@gus-massa](https://racket.discourse.group/u/gus-massa)\
**Post date:** [December 12, 2022, 3:07am UTC](https://racket.discourse.group/t/no-static-type-checking-of-in-list-form-used-in-for/1548/2 "2022-12-12T03:07:04Z")

</div>

Old relevant discussion [`in-list` in comprehension forms type-checks with anything · Issue #781 · racket/typed-racket · GitHub](https://github.com/racket/typed-racket/issues/781)

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [December 22, 2022, 10:15pm UTC](https://racket.discourse.group/t/no-static-type-checking-of-in-list-form-used-in-for/1548/3 "2022-12-22T22:15:09Z")

</div>

Ran into this again, came up with this simple workaround.

```scheme
#lang typed/racket

(define definitely-not-a-list string-length)

(: listy (All (T) ((Listof T) -> (Listof T))))
(define (listy l) l)

(define-syntax (in-list/ck stx)
  (syntax-case stx ()
    [(_ a) #'(in-list (listy a))]))

(for/list : (Listof Real)
  ([i (in-range 4 10)]
   [b (in-list/ck definitely-not-a-list)])
  i)

```

I'll add this comment to the issue as well.
