[racket] specifying types for fields in non-polymorphic structures
On 4/25/14, 9:57 PM, Alexander D. Knauth wrote:
> But then the posn constructor doesn’t enforce that it’s arguments have to be Reals, and the posn? predicate doesn’t check it, and the accessors don’t say that they always produce Reals.
Maybe I'm not seeing the big picture, but that's what the Posn type is
for. If you apply posn to something other than reals, you won't get a
Posn. If you have a Posn and apply posn-x, you get a real.
(define: (f [p : Posn]) : Real
(+ (posn-x p) (posn-y p)))
David
> On Apr 25, 2014, at 9:49 PM, David Van Horn <dvanhorn at cs.umd.edu> wrote:
>
>> How about this?
>>
>> (struct: (x y) posn ([x : x] [y : y]))
>> (define-type Posn (posn Real Real))
>> (define-type Origin (posn Zero Zero))
>>
>>