[racket] require/typed to a struct type

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Fri Feb 8 23:38:05 EST 2013

Its the same reason that this program gives an error.

#lang racket

(define/contract (f x)
  (my-struct? . -> . number?)
  1)

(struct my-struct ())

(f (my-struct))

Do you expect this to work?

We could replace uses of my-struct? with (lambda (x) (my-struct? x)) but I
wonder if the optimizer will see through that or not (Given that it
actually is delaying the resolution of the variable). Also that doesn't
return true to struct-predicate-procedure? and something might depend on
that for optimizations.


On Fri, Feb 8, 2013 at 8:20 PM, Joe Gibbs Politz <joe at cs.brown.edu> wrote:

> When using require/typed with a struct type in the signature, it seems
> to matter if the require comes before or after the struct definition:
>
> typed.rkt
> =========
> #lang typed/racket
>
> (require/typed "untyped.rkt"
>  [number-me (my-struct -> Number)])
>
> (struct: my-struct ())
>
> (number-me (my-struct))
>
> untyped.rkt
> =========
> #lang racket/base
>
> (provide number-me)
> (define (number-me _) 52)
>
>
> Running typed.rkt yields:
>
> my-struct?: undefined;
>  cannot reference an identifier before its definition
>
> But, if I change typed.rkt to
>
> typed2.rkt
> =========
> #lang typed/racket
>
> (struct: my-struct ())
>
> (require/typed "untyped.rkt"
>  [number-me (my-struct -> Number)])
>
> (number-me (my-struct))
>
>
> There's no error and the call succeeds.
>
> Any reason for the ordering dependency?  It's quite inconvenient to be
> shuffling require statements around as soon as you want to put a
> struct in their type, so I'm assuming this wasn't intended.
> ____________________
>   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/20130208/711fb666/attachment-0001.html>

Posted on the users mailing list.