|
> Clojure is dynamically typed in the sense that programs are not type-checked at compile time, values are tagged with types, and type errors are runtime errors. Well, yes, but that has little to do with the way Clojure abstractions work; namely, they're not based on dynamic dispatch, but on OO-style polymorphism. But BTW, your definition is not entirely complete, and the distinction between statically typed and dynamically typed is not always so clear cut when you're not talking about extremes such as Haskell and JavaScript. Statically typed languages like Java, C++, C# and Scala can, and do have runtime type errors because they allow casting. They also all have type tags (well, optional in C++). I.e., most statically typed languages don't attempt to eliminate all type errors at compile time. Clojure indeed does very little static type checks (I think only function arity is checked). Even in Haskell values must be tagged with types, and the type tags are inspected at runtime. Otherwise, pattern matching wouldn't work (pattern matching is always based on type reflection). > I'm curious why you think multimethods are more limited than dynamic dispatch. Because methods can't (or rarely do) "appear out of nowhere" or get installed at runtime as they do in, say, JavaScript or Groovy. |
This does not fit my understanding of pattern matching in Haskell. Say you are matching over a value of type `Maybe String`. The type of the value is always `Maybe String`, it's just that its value might be `Just "foo"` or `Nothing :: Maybe String`. It is not to my knowledge tagged with type information at runtime in a compiled program, merely value information. The different values an ADT disjunction can take on all have the same type as each other.
> Otherwise, pattern matching wouldn't work (pattern matching is always based on type reflection).
What about pattern matching a String against a series of literal values? I don't see how this is based on type reflection, merely inspection of values.