我有以下简单的代码:
; 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)))
如何使用core.typed
注释-main
函数?
答案 0 :(得分:4)
因为-main
函数有多个实现,所以需要显式使用函数类型Fn
,而不是短语法。它看起来像这样:
(ann -main
(Fn [-> nil]
[Any -> nil]))
查看core.typed wiki中的Functions条目,了解有关函数类型语法的更多详细信息。另外,请查看cf
,因为它可以向您展示如何输入表单。
(clojure.core.typed/cf
(fn ([] (println "Hello, World!"))
([x] (println "You gave me " x))))
;; => [(Fn [Any -> nil] [-> nil]) {:then tt, :else ff}]