6 ms·
Clojure's dynamic typing is somewhat different from other languages, though, as it really just has two non-atom types: seqs for collections and maps for data ob
by pron 14y ago
Clojure's dynamic typing is somewhat different from other languages, though, as it really just has two non-atom types: seqs for collections and maps for data objects. Virtually all collections and objects can be manipulated as one of these two types. So "calling a method" on an inappropriate type is basically passing an inappropriate map to a function. You might want to disallow it, but Clojure allows it for good reason: this makes it possible to have many data access/manipulation functions that work on all objects. So the question is, do you want to forbid passing an argument that doesn't make sense to a function or open the door to lots of useful functions that would work on all objects. Clojure simply chose the latter.
- Tuna-Fish 14y ago> this makes it possible to have many data access/manipulation functions that work on all objects. This is not actually true. Add proper type inference and structural typing, and it's perfectly possible to have all those generic data manipulation functions while also having strong static typing.
- nkvoll 14y agoBut using structural typing (on the JVM, where Clojure lives) is slow, because it requires using reflection, which severely limits its use currently.
- Tuna-Fish 14y agoI'm talking about structural static typing. At runtime, all the types would be fully determined, so no need for reflection. (Or vcalls for that matter).
- pron 14y agoHow would you write a general function that prints out the values of all fields of any object (without reflection)?
- stuffihavemade 14y agohttp://www.haskell.org/haskellwiki/Template_Haskell http://www.haskell.org/haskellwiki/Template_Haskell
- pron 14y agoI'm not quite sure, but I don't think this has anything to do with structural typing.