Is it possible to create a language where it's statically typed (preferably with inference) by default, but can drop to dynamic typing for bits where you need it. I seem to remember someone saying this wouldn't work. Can anyone explain why?
Name:
Anonymous2007-09-09 19:00 ID:nWkDjLTQ
This would work. In Haskell you can have values of type Dynamic. However, you have to unwrap them explicitly (conceptually not unlike unboxing in C#, or dynamic_cast<> in C++) and catch the cases when the contents are not of the type you expected.
Generally type inference is about as good, except for heterogenous collections. But I think there's a Haskell library for those, too, and for simple collections (i.e. ones that don't operate on the "leaves" of the structure) you can just use Dynamic or define a datatype with as many distinct leaves as you have types.
In the end, good design tends to make dynamic typing unnecessary. Unify your data model at a higher level, and refactor to fit.