On Mon, Jan 19, 2015 at 9:54 AM, Alexander D. Knauth <alexan...@knauth.org> wrote: > Would there be a more general solution that wouldn’t be specific to just > hash-tables?
I'm not sure what you mean. The code you suggested fixes a hash-table-specific limitation in Typed Racket. If the question is could `overlap` not have so many cases, then I'd certainly like that, but it's very hard to accomplish. In particular, abstractions like `Sequence` and `Evt` overlap with arbitrarily many types. A more principles treatment of such abstractions would help, but we don't yet know how to do that. Sam > > On Jan 19, 2015, at 9:38 AM, Sam Tobin-Hochstadt <sa...@cs.indiana.edu> wrote: > >> This is a correct improvement to Typed Racket -- I'll make it shortly. >> >> Sam >> >> On Mon, Jan 19, 2015 at 8:41 AM, Alexander D. Knauth >> <alexan...@knauth.org> wrote: >>> I managed to fix this for your example by inserting these 3 lines into >>> typed-racket/types/remove-intersect.rkt after line 67: >>> [(list-no-order (Value: (not (? hash?))) >>> (or (? Hashtable?) (? HashtableTop?))) >>> #f] >>> There is probably a better solution though. >>> >>> On Jan 19, 2015, at 7:36 AM, Alexander D. Knauth <alexan...@knauth.org> >>> wrote: >>> >>> Since hash-tables can be mutable as far as TR knows, (HashTable Symbol >>> String) is not a subtype of (HashTable Symbol JSExpr). >>> To work around this, you can do this: >>> #lang typed/racket/base >>> (require typed/json) >>> (: jsx JSExpr) ; <-- jsx is what I ultimately want. >>> (define jsx (ann #hasheq((a . "val1") (b . "val2") (c . "val3")) (HashTable >>> Symbol JSExpr))) >>> >>> Or this would work too: >>> #lang typed/racket/base >>> (require typed/json) >>> (: jsx (HashTable Symbol JSExpr)) ; <-- jsx is what I ultimately want. >>> (define jsx #hasheq((a . "val1") (b . "val2") (c . "val3"))) >>> >>> Or you could use (inst make-immutable-hasheq Symbol JSExpr) instead of using >>> #hasheq, and it would do the same thing. >>> >>> >>> On Jan 19, 2015, at 1:28 AM, Jordan Johnson <j...@fellowhuman.com> wrote: >>> >>> Hi all, >>> >>> I’ve been trying to create JSExprs, as defined in the typed/json library. >>> This is one of those instances where it seems like I must be making things >>> harder than they should be, but I’m still feeling like a duck on >>> rollerskates in TR, so I want to make sure I’m not missing an easier way to >>> do it. >>> >>> Would you please confirm if this is indeed a smallest-possible solution? >>> >>> ;;;; begin >>> #lang typed/racket/base >>> >>> (require typed/json) >>> >>> (: jsx JSExpr) ; <-- jsx is what I ultimately want. >>> >>> ;; Attempt #1: >>> #; >>> (define jsx #hasheq((a . "val1") (b . "val2") (c . "val3"))) >>> >>> #| Resulting error: >>> Type Checker: type mismatch >>> expected: JSExpr >>> given: (HashTable Symbol String) >>> >>> [This seems weird, since it seems like (HashTable Symbol String) should be >>> a subtype of JSExpr. Is the problem that the typechecker can’t recognize >>> the Strings as JSExprs?] >>> |# >>> >>> ;; Attempt #N (shortest successful version I’ve found): >>> (define jsx >>> (for/hasheq : (HashTable Symbol JSExpr) ([k '(a b c)] >>> [v '("val1" "val2" "val3")]) >>> (values k v))) >>> ;;;; end >>> >>> Regards, >>> Jordan >>> >>> ____________________ >>> Racket Users list: >>> http://lists.racket-lang.org/users >>> >>> >>> ____________________ >>> Racket Users list: >>> http://lists.racket-lang.org/users >>> >>> >>> >>> ____________________ >>> Racket Users list: >>> http://lists.racket-lang.org/users >>> > ____________________ Racket Users list: http://lists.racket-lang.org/users