[racket] TR: struct: #:prefab option

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Mon May 6 13:03:32 EDT 2013

Yes, this is basically treating prefab structs like `cons` rather than
like `struct` (which is the right thing to do).

On Mon, May 6, 2013 at 11:46 AM, Eric Dobson <eric.n.dobson at gmail.com> wrote:
> Couldn't this be solved by protecting the struct on export?
>
> #lang racket/load
>
> (module foo racket
>  (struct foo (f) #:prefab)
>  (define x (foo (lambda (x) (* 3.3 x))))
>  (provide/contract
>    (x (struct/c foo (-> number? number?)))))
> (module bar racket
>   (require 'foo)
>   (struct foo (f) #:prefab)
>   ((foo-f x) "foo"))
> (require 'bar)
>
> On Mon, May 6, 2013 at 7:27 AM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
>> On 2013-05-06 10:09:06 -0400, Ray Racine wrote:
>>>    The below is now failing for me.
>>>    (struct: Stuff ([this : String][that : Natural]) #:prefab)
>>>
>>> [...]
>>>
>>>    If there is a typing issue with the use of #:prefab and its banishment
>>>    permanent, is there an alternate best practice mechanism for easy struct:
>>>    serialization/de-serialization?
>>
>> If you're using the Racket pre-release, then that was probably my commit
>> that broke that. Sorry for breaking compatibility here, but it's unsound
>> for TR to admit #:prefab as is. Here's an example:
>>
>>   $ racket
>>   Welcome to Racket v5.3.
>>   -> (module foo typed/racket
>>        (struct: foo ([f : (Float -> Float)]) #:prefab)
>>        (define x (foo (lambda: ([x : Float]) (* 3.3 x))))
>>        (provide x))
>>   -> (module bar racket
>>        (require 'foo)
>>        (struct foo (f) #:prefab)
>>        ((foo-f x) "foo"))
>>   -> (require 'bar)
>>   2.293305645053357e-309
>>
>> The first module exports a #:prefab struct instance containing an
>> optimized (Float -> Float) function. Since it's a prefab, the second
>> module (which is untyped), can freely access the function stored inside.
>>
>> Since the function is unprotected, it does an unsafe multiplication on a
>> string and no contract error is raised.
>>
>> I'm not sure what's a good alternative for serialization in TR off the
>> top of my head.
>>
>> Cheers,
>> Asumu
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.