On Fri, Nov 20, 2015 at 3:27 AM, Antonio Menezes Leitao <
antonio.menezes.lei...@ist.utl.pt> wrote:

> Hi,
>
> On Thu, Nov 19, 2015 at 11:36 AM, WarGrey Gyoudmon Ju <
> juzhenli...@gmail.com> wrote:
>
>> 1. define structs in untyped racket;
>> 2. (require/typed/provide) it with #:constructor-name option.
>>
>>
> Thanks for the suggestion.
>
> Meanwhile, I thought about a different approach. Here is one example:
>
> (module test typed/racket
>   (struct foo
>     ([a : Real]
>      [b : Integer]))
>   (provide (except-out (struct-out foo) foo)
>            (rename-out [foo new-foo])))
>
> (require 'test)
>
> (define f (new-foo 1.0 2))
>
> (foo-a f)
>
> (foo-b f)
>
> Can you (or someone else) comment on the advantages of these two
> approaches?
>

Generally speaking, Racket Struct is not only a compact data collection
(like a vector with fields accessors, benefits both compiler and human
readers), Struct itself also has their own properties and methods to define
generic interfaces which is widely known in Class-based System (ignoring
that Racket Class-based System is also implemented in terms of Struct, they
are different things but have same effects).

Currently, Typed Racket only treats Struct as the compact data collection,
therefore, if you want to take full advantages of Struct, defining it in
untyped module than requiring it in typed module is the only choice, but
not vice versa.

I never tried your approach in practice, and you have already known the
side effects. Nonetheless, if you don't like the untyped way. How about
just defining one more function to make its instance? In this way, you also
have a more flexible guard procedure (see #:guard option). Besides I just
cannot understand the design of #:auto and #:auto-value options, it's so
weird that almost makes nonsense.


>
> Finally, can we define syntax to wrap both the module and the require? Is
> it possible for a macro to expand into such combination of forms? My quick
> experiments didn't produce the results I was expecting.
>

I found it impossible too.


>
> Best,
> António.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to