clojure sequence type
Asked Answered
H

1

5

What's the correct type of a sequence? I have this code:

(defrecord MethodInfo [^clojure.lang.ISeq preconds ^clojure.lang.ISeq postconds])

But it doesn't seem to correctly enforce the type requirements, since I can write (new MethodInfo 1 2).

Hyoscyamine answered 17/7, 2011 at 23:25 Comment(0)
T
7

My understanding is that Clojure's Type Hints are only there for performance reasons, to improve method lookup by side-stepping reflection; That is their only purpose, and not to enforce static types in a dynamic language.

Please see this answer to a similar question.

Edit:

There is talk of being able to enforce primitive return types in some cases in Clojure 1.3, but this is clearly something that's in flux, and still wouldn't apply to sequence types.

Tractate answered 18/7, 2011 at 1:37 Comment(1)
Mostly true. You can typehint in a definterface, and the interface generated will have fields of the right type. That's strictly for interop purposes, though, and you're right about not enforcing static types in general.Subtraction

© 2022 - 2024 — McMap. All rights reserved.