[racket] TR: struct: #:prefab option

From: Ray Racine (ray.racine at gmail.com)
Date: Mon May 6 13:40:08 EDT 2013

Asumu,

Not sure I follow.  If one uses a typed function imported into untyped
Racket all bets are off.

(module foo typed/racket
  (provide double)
  (: double (Integer -> Integer))
  (define (double x)
    (+ x x)))

(module bar racket
  (require 'foo)
  (double "2"))

(require 'bar) ;; fails




On Mon, May 6, 2013 at 10: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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130506/ace89b55/attachment.html>

Posted on the users mailing list.