[racket] naming structs that are members of other structs

From: Ray Racine (ray.racine at gmail.com)
Date: Wed Feb 13 17:22:03 EST 2013

In TR I mostly see types with a leading capital letter which generally
avoids such conflicts.

#lang typed/racket

(define-type Coords (Pairof Real Real))
(define-type Velocity Real)
(define-type Color (U 'Red 'Blue 'Green))
(define-type VehicleModel (U 'Ford 'Lada))

(struct: Vehicle-State ([position : Coords]
                       [velocity : Velocity]))

(struct: Vehicle ([state : Vehicle-State]
                  [color : Color]
                  [model : VehicleModel]))

(define: velocity :Velocity (Vehicle-State-velocity (Vehicle-state v)))

Also easier to glance read with cases such as ...
 (Vehicle-State-state vs)
(Vehicle-state v)

FWIW I camel-case my types.  VehicleState vs. Vehicle-State.


I've never thought it through but one day I've had a passing thought about
the some sort of l-struct macro which creates/associates generics "Lens"
getter/setters to the defined structure.



On Wed, Feb 13, 2013 at 3:38 PM, Dmitry Pavlov <dpavlov at ipa.nw.ru> wrote:

> Danny, I would not treat this problem as similar to
> the helper() function name conflict you mentioned.
> Having two structures referring to each other
> in the same module is a much lesser sin than
> having two equally named things in the same module.
>
> So I would prefer to solve this with a proper naming
> convention within a module, rather than putting each
> struct inside its own module.
>
>
> Stephen, thanks for the tip about the #:constructor-name.
> I think I may use that. Another solution, which just
> came to my head, is naming the structure
> vehicle/state instead of vehicle-state.
>
> Best regards,
>
> Dmitry
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130213/a9e357fd/attachment.html>

Posted on the users mailing list.