typedclojure / typedclojure

An optional type system for Clojure
Eclipse Public License 1.0
479 stars 7 forks source link

Missing annotations #133

Open triHims opened 7 months ago

triHims commented 7 months ago

How to work around missing annotations ?

(defn readCsv
  "Read CSV call a function"
  [csvname _fn]
  (with-open [rdr (clojure.java.io/reader csvname)]
    (_fn (line-seq rdr))))

I have this function. Its not annotated. Frankly i do not want to check it with check-ns but when i run check-ns to check other functions. I get error because line-seq is not found.

ps. I am new to eco system so apologies if its a waste of time.

triHims commented 7 months ago

this is the way to add types for unannotated functions.

(t/ann clojure.core/line-seq [BufferedReader :-> t/Seqable])

This talk kinda gives me some foundation on how to approach this https://www.youtube.com/watch?v=8oW4Wm09ilk

How to infer types https://www.youtube.com/watch?v=zcxOWE7MuOY

But Still i am not sure ? for these common types can i write them into a seperate file that can be used by entire project ?

triHims commented 7 months ago

Documenting this ticket , in case anyone stumbles upon it.

in your name space declaration you can use

(ns service.job
  {:core.typed {:experimental #{:infer-vars}}}
  (:gen-class)
)

This will generate annotations for all the functions (Annotations will be of type Any ).

frenchy64 commented 7 months ago

Use ^:no-check metadata to give an annotation to a function without checking the var.

(t/ann ^:no-check readCsv [...->...])