4 ms·
The great thing about languages that implement HM types is that they allow you work as quickly or as carefully as you'd like without needing to change languages
by ohazi 6y ago
The great thing about languages that implement HM types is that they allow you work as quickly or as carefully as you'd like without needing to change languages.
If you've done something a million times before and are familiar with how it works, you can leave off all the type hints, and it'll figure them out for you and stay out of your way so that you can work more quickly. If you make a mistake somewhere, the compiler will still tell you.
If you're doing something new, or don't quite understand something, you're free to add type hints wherever you need them to gain clarity. You can even do stuff like:
let var: () = ...;
if you have no idea what type something is and just want to ask the compiler for help.
Once you're done, you can tidy up if you think it makes your code more readable. You can still leave top level hints to be kind to your coworkers or future you.
I think the ability to dynamically shift between "cautious exploratory mode" and "reckless I-know-what-I'm-doing mode" at the drop of a hat is why you hear a lot of anecdotes about people using languages like OCaml or Rust as if they were scripting languages.
- CDSlice 6y agoTo expand on this, if you use CLion as your Rust IDE it will actually show you the types for all your variables automatically. For example, if you had a line like this: let foo = vec![1, 2, 3]; CLion would then show the type in a faded font where the type would go if you wrote it out manually like so: let foo: Vec<i32> = vec![1, 2, 3]; This is extremely useful when working with more complicated types such as iterator chain because it lets you see exactly what type everything is without having to manually write it all out and have the compiler check it.
- riquito 6y agoThat's available with VSCode and rust-analyzer too (but I suspect others that piggyback on rust-analyzer got that ability). It can get noisy fast, but you can toggle hints for when you need them
- frank2 6y agoHaskell, which uses a HM type system, has a type called Dynamic, which is described as follows: >Finally, dynamically typed programming in Haskell made easy! Tired of making data types in your Haskell programs just to read and manipulate basic JSON/CSV files? Tired of writing imports? Use dynamic, dynamically typed programming for Haskell! [1] If using an HM type system is really as easy and as fluid as you suggest, what purpose would be served by a type such as Haskell's Dynamic? Nor is Dynamic a panacea: to use it requires a lot of extra typing (er, extra keypresses) IIRC, and >A Dynamic may only represent a monomorphic value; an attempt to create a value of type Dynamic from a polymorphically-typed expression will result in an ambiguity error (see toDyn). [2] 1: https://hackage.haskell.org/package/dynamic https://hackage.haskell.org/package/dynamic 2: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Dynamic.html#t:Dynamic https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-...
- aweinstock 6y agoIt's probably worth noting that the majority of the development on that library was done on April 1st 2019.
- frank2 6y agoThe relevant file of source code has, "Copyright (c) The University of Glasgow 2001", which jibes with my memory of having used Dynamic in GHC in 2004 or earlier: https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.Dynamic.html https://hackage.haskell.org/package/base-4.14.0.0/docs/src/D... Also notice that Dynamic is in the Haskell Package Repository's "base" package, described as containing "Basic libraries", not part of an ancillary area for user-contributed libraries: https://hackage.haskell.org/package/base-4.14.0.0 https://hackage.haskell.org/package/base-4.14.0.0 There exist type systems of which great grandparent is an accurate description (the most well-known of which is probably that used by Typescript) but the type system of, e.g., Haskell, Ocaml or Rust is not it. (Now I am getting curious what specific programming language's type system great grandparent had in mind.)
- zenhack 6y ago