Annotating external libraries

67 views
Skip to first unread message

Sven Richter

unread,
Apr 3, 2015, 4:18:17 AM4/3/15
to clojure-c...@googlegroups.com
Hi,

I just tried out core.typed again as I understand clojure itself better. I still like the idea, but what bugs me now is that I have to annotate every external function call that does not belong to me. I know the reasoning behind this and do not question the need of it.

1. There will be a lot of clutter in my namespace just because of external calls.
2. There will be a lot of duplication not only inside my application, but also across all applications using core.typed and external libraries.

Does it make sense to start a community powered repo on github (or whereever) to provide annotations to common libraries which then can just be loaded when I need them? This will both solve problem number one and two I guess.

Best Regards,
Sven

Ambrose Bonnaire-Sergeant

unread,
Apr 3, 2015, 3:48:55 PM4/3/15
to core.typed
I agree this is a problem, and we need some sort of centralised repo. The build process will be important.

We should be able to specify annotations for multiple versions of the same jar. Say 

(lib-annotations
     {:provides-versions #{"0.1" "0.2" "0.3-SNAPSHOT"}
      :requires {:all '((:requires [clojure.core.typed :as t] [my.lib :as lib]))}
      :configs
      #{(for-version
          #{"0.1" "0.2"}
          {lib/foo '[(t/Coll t/Int) t/Int -> t/Int]})
        (for-version
          #{"0.3-SNAPSHOT"}
          {lib/foo '(t/Fn [(t/Transducer t/Int t/Int) -> t/Int] 
                          [(t/Coll t/Int) t/Int -> t/Int])})}}})

generates:

;; org/typedclojure/ann/my.lib-0.{1,2}.jar/project.clj
======================================================
(defproject org.typedclojure.ann/my.lib-0.{1,2} "0.2.423"
  :dependencies [[my.org/my.lib "0.{1,2}"]
                 [org.clojure/core.typed "LATEST"]])



;; org/typedclojure/my.lib-0.{1,2}.jar/org/typedclojure/ann/my/lib.clj
======================================================================
(ns org.typedclojure.ann.my.lib
  (:require [clojure.core.typed :as t]
                 [my.lib :as lib]))

(t/ann lib/foo [(t/Coll t/Int) t/Int -> t/Int])



;; org/typedclojure/ann/my.lib-0.3-SNAPSHOT.jar/project.clj
======================================================================
(defproject org.typedclojure.ann/my.lib "0.2.423"
  :classifier {:0.3-SNAPSHOT
  :dependencies [[my.org/my.lib "0.3-SNAPSHOT"]
                 [org.clojure/core.typed "LATEST"]])



;; org/typedclojure/ann/my.lib-0.3-SNAPSHOT.jar/org/typedclojure/ann/my/lib.clj
======================================================================
(ns org.typedclojure.ann.my.lib
  (:require [clojure.core.typed :as t]
                 [my.lib :as lib]))

(t/ann lib/foo (t/Fn [(t/Transducer t/Int t/Int) -> t/Int] [(t/Coll t/Int) t/Int -> t/Int]))


Thanks,
Ambrose

Sven Richter

unread,
Apr 4, 2015, 4:16:02 AM4/4/15
to clojure-c...@googlegroups.com
Hi Ambrose,

This looks like a good solution. However, I myself don't have a clue on how to split up namespaces into different jars during a build process with leiningen (or whatever).
The farthest I have come in my mind is to just use different namespaces for library/version combination, which will include duplication too, obviously, but kept in one lib instead of many others.

Do you have an example on github somewhere where people generate different jar files depending on some reader macros like in your example? I would like to look at something existing and see if I can adapt that.

Best Regards,
Sven
Reply all
Reply to author
Forward
0 new messages