3 ms·
> Actually, languages with rich type systems in general seem to really struggle in this space. I suspect there's two factors. First, I think the current crop
by dwohnitmok 6y ago
> Actually, languages with rich type systems in general seem to really struggle in this space.
I suspect there's two factors.
First, I think the current crop of languages with "rich type systems" (I imagine you're thinking of Haskell, Scala, ML and the like?) basically all are in this weird uncanny valley where people get tempted into trying all sorts of cool type tricks to make everything line up, and the type systems are just not _quite_ expressive enough to make it all go well.
Most of the time if you just use arrays/your language's usual collection type of numbers (or arrays of arrays... etc.) in those static languages you'll do great.
To take it to next level and really model ML faithfully I think you probably will need some version of dependent types and there just aren't really any good implementations of that at the moment.
Secondly, a lot of ML is powered by data scientists and statisticians to whom dynamic languages mesh probably better with their own educational background (when was the last time you saw types written out in a stats textbook?). It's really kind of jarring and annoying to have to deal with type systems when you've never done any professional programming before.
- bgorman 6y agoWhat I have seen in the wild is that in dynamic languages programs end up being "stringly" typed, where a mistyped string in the program results in an error, and programs needlessly rely on array positioning. ML languages that support variants eliminate these unnecessary errors are no cost to runtime performance. What problems have you encountered where a ML system couldn't represent things better than primitive type system? The two things that come to my mind are when the program has to accept arbitrary user input (strings), and writing an extremely expressive program i.e. a lisp interpreter with support for variable argument length functions. Even in these cases, I think the guarantees around the messy sections help with refactoring and my general sanity.
- dwohnitmok 6y ago> What problems have you encountered where a ML system couldn't represent things better than primitive type system? I assume you mean a primitive type system to be a strict subset of an ML type system? So in that case the answer in theory is clearly negative. The problem is more that ML type systems give you more, and fool you into thinking that's enough to try to use the extra bits, when that's not quite enough. > ML languages that support variants eliminate these unnecessary errors are no cost to runtime performance. Closed variants are fantastic. I love them. I miss them every time I use a programming language without them. What I'm talking about is requirements like making sure that all your matrix dimensions line up (you mention variadic arguments, which is another good one if you're trying to follow a lot of mathematical notation). A lot of ML-inspired statically typed languages let you come really close to making all that work. But are just unergonomic enough to make things painful if you really try to statically verify those things.
- bgorman 6y agoMakes sense, thanks for the explanation.