[racket] TR: struct: #:prefab option
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