3 ms·
Does anyone here know how Standard ML inferred types? I really loved coding in SML and its strongly type checking system. The amount of bugs I produced was noti
by hangonhn 3y ago
Does anyone here know how Standard ML inferred types? I really loved coding in SML and its strongly type checking system. The amount of bugs I produced was noticeably less. What I'm wondering is why we can't use a similar system as SML to infer the types. Other languages haven't adopted a similar system so there must be some kind of trade off. What was the downside?
- valcron1000 3y agoLook up 'Hindley–Milner type system'. AFAIK, one feature that break this system is subtyping which is very common in many programming languages.
- nyssos 3y agoYou can't do full nominal subtyping, so no high church OO, but you can add subtyping for records without too much trouble.
- mrkeen 3y ago> What I'm wondering is why we can't use a similar system as SML to infer the types. We can and do! Use SML! People just don't find out about the good type systems because the market is crowded out by mainstream shit. And people write pieces about how good this shit is: "I was going to add an Int to a String but the compiler stopped me! Less [sic] bugs!". With arguments like that, why would you switch camps? Or sometimes you get fed shit and get told it's inference: "I can replace the first word on the line with 'var'!". So what are the downsides? Inference doesn't play well with inheritance or mutability. If you read Effective Java and see the points about avoiding mutation and inheritance, then these downsides may very well seem like upsides to you. Why did you stop coding in SML?
- hangonhn 3y agoSML has never been used in any of the jobs I've had. I definitely have a very functional programming bend to my preferences. The closest I've come to doing something like SML for work is to use Clojure.
- nyssos 3y ago> Does anyone here know how Standard ML inferred types? SML uses Hindley-Milner (with some modifications to support imperative code). Many statically typed functional languages descend from it: Haskell and OCaml are the most prominent. > Other languages haven't adopted a similar system so there must be some kind of trade off. What was the downside? If you're asking why existing popular languages don't adopt it: they can't. HM type inference requires a HM type system, and they've committed to a different one. At best you could get good inference on a HM-typed fragment within the language (though even that would mean making a lot of painful tradeoffs) but it would break down the moment it made contact with existing code. If you're asking why HM languages didn't become more popular? Historical accident, in my opinion. I don't think it has much to do with the type system, given how fundamentally awful Java's is.