Skip to content

Instantly share code, notes, and snippets.

@nathanic
Created October 2, 2013 20:47
Show Gist options
  • Save nathanic/6800305 to your computer and use it in GitHub Desktop.
Save nathanic/6800305 to your computer and use it in GitHub Desktop.
Nathan fails to understand something about assoc'ing onto an HMap with :optional keys
(ns example.typetest
(:use [clojure.core.typed]))
; using [org.clojure/core.typed "0.2.13"]
(def-alias House "a House has some :people in it and maybe a :mortgage."
(HMap :mandatory {:id String
:people (Coll String)
}
; comment out this :optional line and it all works
:optional {:mortgage Number}
))
(ann my-house House)
(def my-house {:id "foo", :people ["Larry" "Curly" "Moe"]})
(comment
(check-ns) ;=> success
(cf (assoc my-house :people ["Shemp"]) House)
;; this will return `House` if the :optional field above is commented out.
;;
;; but if the :optional field is left in the def-alias above, I get:
;Type Error (...) Cannot assoc args `[(Value :people) {:then tt, :else ff}] [[(Value "Shep")] {:then tt, :else ff}]` on typetest/House
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment