3 ms·
Hindley-Milner type systems to the rescue! (With a sprinkling of Haskell style type classes.) f :: Iterable a => a -> b f x = (do stuff with x...) f is de
by pja 14y ago
Hindley-Milner type systems to the rescue! (With a sprinkling of Haskell style type classes.)
f :: Iterable a => a -> b
f x = (do stuff with x...)
f is defined to be constrained to accept only on types which implement the Iterable interface (however that's defined) as it's first argument and the compiler (or interpreter) will enforce that constraint.
- emillon 14y ago> Hindley-Milner type systems to the rescue! You're implying that all type-systems derived from HM have a form of bounded polymorphism. They're not, for example OCaml does not have type classes (you could probably encode a lot into objects, though).
- carterschonwald 14y agoFalse, ocaml has type classes now! (or maybe I'm thinking of coq)
- pja 14y agoI don't think so: If you want the equivalent of Haskell type classes in OCaml then you have to either use a functors or some sort of class IIRC. I'm sure Oleg will have done something though. I believe they're experimental in Coq.
- carterschonwald 14y agoyup, you're right, you got to use functors or go home. Yeup, some folks did show the functors + modules \equiv type classes in some sense, for system F or a variant thereof. Theres also an oleg approach too I think.
- gtani 14y agoTYpe classes and the ML module system overlap in capabilities http://www.cse.unsw.edu.au/~chak/papers/WC06.html http://www.cse.unsw.edu.au/~chak/papers/WC06.html
- Dn_Ab 14y agoOCaml's nephew, F# does have bounded polymorphism though. Although it inherits that from the OOP side of its family.