Skip to content

Instantly share code, notes, and snippets.

@mpenet
Last active December 15, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpenet/5175786 to your computer and use it in GitHub Desktop.
Save mpenet/5175786 to your computer and use it in GitHub Desktop.
(use 'clojure.core.typed)
;; I would like to only allow {:a 1} {:b 2} or {:a 1, :b 2}
(def-alias A '{:a '1})
(def-alias B '{:b '2})
;; naive version would be to use a Union
(ann foo [(U A B) -> (Value 1)])
(defn foo [x] 1)
;; but this type checks :(
(cf (foo {:b 2 :a nil}))
;; I could create HMaps with all the possible k/v possible (and using :optional) for these
;; but I guess there is a better way (short of using macros).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment