Weird, I thought I tried that, Anyway, now it works: Thank you
________________________________________ Van: sam...@gmail.com <sam...@gmail.com> namens Sam Tobin-Hochstadt <sa...@cs.indiana.edu> Verzonden: woensdag 17 februari 2016 16:29 Aan: Bert De Ketelaere CC: us...@racket-lang.org Onderwerp: Re: [racket-users] Hashtable type inference The problem is unfortunately with Typed Racket heuristics that work very badly here. The fix is to add some annotations around the calls to `make-immutable-hash`, as in the version below. Sam #lang typed/racket/base (struct H ([I : (HashTable Integer Number)])) (define J (cast 1 Nonnegative-Integer)) (define K (H (make-immutable-hash (list (cons J J))))) (struct-copy H K [I (ann (make-immutable-hash (list (cons J J))) (HashTable Integer Number))]) ;make-immutable-hash is type (HashTable Integer Integer) which is not compatible with (HashTable Integer Number) (struct U ([V : (HashTable Nonnegative-Integer Integer)])) (define W (cast 1 Nonnegative-Integer)) (define Y (cast 2 Integer)) (define X (U (make-immutable-hash (list (cons W Y))))) (struct-copy U X [V (ann (make-immutable-hash (list (cons W Y))) (HashTable Nonnegative-Integer Integer))]) On Wed, Feb 17, 2016 at 10:19 AM, Bert De Ketelaere <bed...@hotmail.com> wrote: > Hello, > > > I had some trouble finding my bugs in the following similar programs: > > > #lang typed/racket/base > > (struct H ([I : (HashTable Integer Number)])) > (define J (cast 1 Nonnegative-Integer)) > (define K (H (make-immutable-hash (list (cons J J))))) > > (struct-copy H K [I (make-immutable-hash (list (cons J J)))]) > > ;make-immutable-hash is type (HashTable Integer Integer) which is not > compatible with (HashTable Integer Number) > > > (struct U ([V : (HashTable Nonnegative-Integer Integer)])) > (define W (cast 1 Nonnegative-Integer)) > (define Y (cast 2 Integer)) > (define X (U (make-immutable-hash (list (cons W Y))))) > > (struct-copy U X [V (make-immutable-hash (list (cons W Y)))]) > > ;make-immutable-hash is of type (HashTable Integer Integer) while (list > (cons W Y)) is of the right type: (Listof (Pairof Nonnegative-Integer > Integer)) > > > In my program the problem was because of unions (I tried updating with a > hash with only 1 of the union types) > > > Kind regards, > > Bert > > -- > 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. -- 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.