[racket] specifying types for fields in non-polymorphic structures

From: Alexander D. Knauth (alexander at knauth.org)
Date: Fri Apr 25 21:38:31 EDT 2014

Is there a way of specifying types for fields in non-polymorphic structures?  Like this:
(struct: posn ([x : Real] [y : Real]))
(define-type Origin
  (posn Zero Zero))
I know this doesn’t work, but is there something that could work like it?  
By the way is there any reason why the same posn type couldn't be able to be both by itself and with arguments like this?  

Or is there a way of specifying types for fields in polymorphic structures while still enforcing that each field has a certain type?  Like maybe using some kind of And operator (analogous to and/c)?
(struct: (x y) posn ([x : (And Real x)] [y : (And Real y)]))
(define-type Origin
  (posn Zero Zero))  ;=> (posn (And Real Zero) (And Real Zero))

I looked to see if there was an And operator, and I couldn’t find it, but maybe it’s there somewhere else under a different-name, like the Or-like operator (analogous to or/c) is named U?  

By the way, is there a Not operator (analogous to not/c)?




Posted on the users mailing list.