2010/11/22 David Nolen <dnolen.li...@gmail.com> > On Mon, Nov 22, 2010 at 8:00 AM, Ralph <grkunt...@gmail.com> wrote: > >> At first this surprised me, since Clojure is dynamically typed, while >> F# is statically typed. After some thought, however, it occurred to me >> that Clojure can generate code very similar to statically typed >> languages using type hints. Of course, as soon as you add type hints, >> the code is no longer dynamically typed, but rather statically type. >> You lose the ability to do duck-typing on the arguments to a function. >> > > Type hints do not enforce anything. You can pass arguments of the wrong > type to a type hinted function. > > (defn foo [^String x] x) > (foo {}) ; works fine >
Hello, to further explain on the example: type hints are there to avoid compiling into bytecode which would use host reflection features (which cost a lot, especially if the code is called in tight loops). So the type hint info is used by the compiler inside the compilation of the body of the foo function, everywhere there will be "host (e.g. java)" interoperability method call/property access on variable x. In the above example, there is no "host interoperability call" to x property, and that's why the code * compiles succesfully * runs successfully One can also argue that for the above code example, the type hint is totally useless :) Type hints can somehow serve as a man's poor "compile-time strong typing checker", since if there is a mismatch between the type hint and an interop call inside the function's body, the compiler will complain. But this will only "work" for host (e.g. java) interoperability calls, and is not the primary intent of the "type hint" feature, as David said. HTH, -- Laurent > > >> For those cases where performance is more important than flexibility, >> Clojure offers an advantage over "traditional" dynamic languages >> (Ruby, Python, etc.) in that the programmer can choose. >> > > Type hints are only about performance not about losing flexibility. > > The performance guarantees of Clojure (and that story just keeps getting > better and better) combined with it's dynamism are it's biggest draw for > many people. > > David > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > 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 post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en