typed-racket
typed-racket copied to clipboard
[Feature Request] Applicable Type Variables
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.
Should this be transferred to the typed-racket repository?
...well this is embarassing. Yes, it should! I did not remember that that's a separate repo.
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 (-> * *)
.
One response to the 2020 TR survey (out of 106 total) asked for this feature too.