Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `:-` mean in clojure's core.typed?

Tags:

types

clojure

What does :- mean in this code from the core.typed library?

(t/ann play-many [(ta/Chan RPSResult) t/Int -> (t/Map t/Any t/Any)])
(defn play-many
  "Play n matches from out-chan and report a summary of the results."
  [out-chan n]
  (t/loop [remaining :- t/Int, n                          ;; <======== This line
           results :- (t/Map PlayerName t/Int), {}]
    (if (zero? remaining)
      results
      (let [[m1 m2 winner] (a/<!! out-chan)]
        (assert m1)
        (assert m2)
        (assert winner)
        (recur (dec remaining)
               (merge-with + results {winner 1}))))))
like image 592
Ryan Kung Avatar asked Nov 19 '14 15:11

Ryan Kung


2 Answers

As mentioned, :- is just a keyword. However, in your context it's part of core.typed's annotations, marking loop bindings as being of a specific type:

(t/loop [remaining :- t/Int, n
         results :- (t/Map PlayerName t/Int), {}]
  ...)

This means that remaining is an integer, while results is a map associating a player name with an integer. These can be verified using core.typed's type checker.

like image 187
xsc Avatar answered Nov 11 '22 16:11

xsc


:- is a keyword of a single character, -.

user=> :-
:-
user=> (class :-)
clojure.lang.Keyword
like image 45
Tomo Avatar answered Nov 11 '22 15:11

Tomo