Re:Clojure 2014 Year in Review
by weavejester on Saturday January 03, 2015 @10:17AM
(#8830900)
Protocols and records exist purely for polymorphism. If you want type safety, then perhaps try core.typed:
(defalias Point
(HMap :mandatory {:x Num, :y Num}
:complete? true))
(ann add-vectors [Point Point -> Point])
(defn add-vectors [a b]
{:x (+ (:x a) (:x b))
:y (+ (:y a) (:y b))})
Since you mentioned you were learning, I thought I'd share that, although I like functions-on-data as much as the next guy, I often use protocols and records for tasks like this, generally for no reason other than organization and self-documentation:
I think this has more to do with type-safety than object-orientation though.