Reputation: 1608
I have the following simple code:
; No, test.core isn't the real namespace
(ns test.core
(:gen-class)
(:require [clojure.core.typed :refer [ann]]))
(defn -main
([]
(println "Hello, World!"))
([x]
(println "You gave me " x)))
How would I annotate the -main
function using core.typed
?
Upvotes: 3
Views: 370
Reputation: 5231
Because the -main
function has more than one implementation, you need to explicitly use the function type, Fn
, instead of the short syntax. It would look something like this:
(ann -main
(Fn [-> nil]
[Any -> nil]))
Take a look at the Functions entry, in the core.typed wiki, for more details on the syntax of the function type. Also, take a look at cf
, because it can show you how to type forms.
(clojure.core.typed/cf
(fn ([] (println "Hello, World!"))
([x] (println "You gave me " x))))
;; => [(Fn [Any -> nil] [-> nil]) {:then tt, :else ff}]
Upvotes: 4