typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

[Feature Request] Applicable Type Variables

Open nick-chandoke opened this issue 3 years ago • 4 comments

It'd be very useful to be able to apply type variables to other types. An example use case is parameterizing a UI component by its layout, where a layout is a container of components, e.g. a list or tree:

(define-type (Container% Layout) (Object (field [components (Layout Component%)])))

To borrow Haskell's notation, Layout :: * -> *, i.e. is unary-kinded type variable. Tree or Listof are appropriate values for it.

This currently gives the type error, "type cannot be applied."

The only alternative I know of is making variable the whole type, which is less safe. For example, rather than (define-type (T f) (f Integer)) I can only use the unconstrained type variable T, and only instruct users of the library to ensure that T is unary-kinded and is always parameterized by Integer.

I don't have any experience with working on typed racket (or racket in general), but if it's easy enough to do, then I'd be happy to give it a try.

nick-chandoke avatar Jan 19 '21 21:01 nick-chandoke

Should this be transferred to the typed-racket repository?

AlexKnauth avatar Jan 19 '21 21:01 AlexKnauth

...well this is embarassing. Yes, it should! I did not remember that that's a separate repo.

nick-chandoke avatar Jan 19 '21 21:01 nick-chandoke

This would definitely be good. Unfortunately, I think making it work would require major changes to how Typed Racket handles polymorphism. The kind system in Typed Racket was poorly designed at the beginning and thus this is hard to fix. In particular, Listof has kind *, rather than kind (-> * *).

samth avatar Jan 20 '21 20:01 samth

One response to the 2020 TR survey (out of 106 total) asked for this feature too.

bennn avatar Jan 21 '21 03:01 bennn