Exactly! the compiler throws the reflection warnings, I want to type hint
for the input parameters to eliminate the warnings.
On Sunday, January 12, 2014 8:58:14 PM UTC+8, Jim foo.bar wrote:
>
> In order to do that you would have to reach to the interface behind the
> protocol...observer this:
>
> user=> (defprotocol P (f1 [_] nil))
> P
> user=> P
> {:on-interface user.P, :on user.P, :sigs {:f1 {:doc "YES!", :arglists
> ([_]), :name f1}}, :var #'user/P, :method-map {:f1 :f1},
> :method-builders {#'user/f1 #<user$eval695$fn__696
> user$eval695$fn__696@5dc4352a>}}
> user=> (defn ftest [^P arg] (str arg))
> CompilerException java.lang.IllegalArgumentException: Unable to resolve
> classname: P, compiling:(NO_SOURCE_PATH:1:1)
> user=> (defn ftest [^user.P arg] (str arg))
> #'user/ftest
> user=> (ftest :foo)
> ":foo"
>
> So, yes the compiler will let you do it but it won't actually enforce
> it! May I ask why would you want to do this? Are you hitting any
> reflection?
>
> Jim
>
>
>
> On 12/01/14 12:38, bob wrote:
> > Hi,
> >
> > Is it possible to add type hint (the type is protocol) to funs?
> >
> > for example:
> >
> > (defprotocol IProtocol
> > (f1 []))
> >
> > can we define fn like this?
> > (defn ftest
> > [^IProtocol arg]
> > (.toString arg))
> > --
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to [email protected]<javascript:>
> > Note that posts from new members are moderated - please be patient
> > with your first post.
> > To unsubscribe from this group, send email to
> > [email protected] <javascript:>
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> > ---
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.