[racket] TR: JSExprs and hashtables

From: Jordan Johnson (jmj at fellowhuman.com)
Date: Mon Jan 19 01:28:02 EST 2015

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150118/a8cbbd0c/attachment-0001.html>

Posted on the users mailing list.