Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to type hint

Tags:

clojure

How would I type hint this to get rid of the remaining reflection calls?

(def B 
     (amap ^"[[D" A i ^"[[D" B 
          (amap ^doubles (aget A (int i)) j ^doubles row 
             (* 2 (aget row (int j))))))

There's two reflection calls left, but I don't know how to get rid of them.

like image 439
2daaa Avatar asked Sep 23 '10 15:09

2daaa


1 Answers

You don't show your complete code or the reflection warnings, but if they are what I think they are, you'll need to:

  1. hint A: (def ^"[[D" A ...) wherever you define it
  2. cast the return value of the innermost expression to double: (double (* 2 ...))

The process to come up with these fixes is to perform macroexpand on the macro, run that version, see what expressions are causing the reflection warnings, fix them, and hope that you can retrofit the hints into the original macro, which in this case is possible. I still recommend the more straightforward solution.

like image 183
Jouni K. Seppänen Avatar answered Oct 03 '22 22:10

Jouni K. Seppänen