|
|
|
|
|
by xapata
3568 days ago
|
|
> you can have your cake and eat it, too. Like a dynamic language with optional type hints? As I said, both techniques can mimic each other, with the corresponding tradeoffs. As you use more generics in a statically typed language, you're sacrificing safety. As you use more type hints in a dynamically typed language, you're increasing syntax clutter and decreasing flexibility. |
|
Actually, in languages like Haskell, the more generic your type, the more "safe" you can expect it to be.
As an example, consider a function that gives you the first element of the tuple you pass to it.
The most generic type of this function is
However, it can also have the type Now, you can be sure of the behaviour of fst immediately by looking at its type, but that doesn't hold for fst1Pretty much the only definition of fst that the compiler will accept is
However, the compiler will accept all the following definitions of fst1