Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

[0; 'a'; fun x -> x + 1];;

The common type is object, or perhaps more specifically, non-nil object (object!), if 0 is not treated as nil (value type).

If you try to interact with an object (add it to a number, call a method, etc.), your language has to decide what to do: fail because that method is not part of the type object, or force people to cast to the proper sub-type, or allow a kind of dependent typing/casting (if type(it)=int: it+1 else if type=char: it.uppercase), or (like boo, python, ruby, etc.) allow "duck typing": allow any calls/methods on the object, and check it at run-time instead of compile-time



Not all type systems allow for subtyping. In particular, Hindley-Milner does not. Nor, as far as I'm aware, do any of the consistently-typed proof languages (like Agda, Coq, etc.)


Typing in the Haskell et. al. tradition don't like subtyping. And they also like their parametericity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: