News for hackers. Stuff that matters.
Re:Hindley-Milner Type Inference (2012) by ohazi on Friday July 10, 2020 @03:56PM (#23795687)
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.

Re:Hindley-Milner Type Inference (2012) by CDSlice on Friday July 10, 2020 @04:15PM (#23795920)
To 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.
Re:Hindley-Milner Type Inference (2012) by riquito on Saturday July 11, 2020 @12:53AM (#23799611)
That'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
Re:Hindley-Milner Type Inference (2012) by frank2 on Friday July 10, 2020 @07:33PM (#23797861)
Haskell, 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

2: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-...

Re:Hindley-Milner Type Inference (2012) by aweinstock on Friday July 10, 2020 @08:41PM (#23798319)
It's probably worth noting that the majority of the development on that library was done on April 1st 2019.
Re:Hindley-Milner Type Inference (2012) by frank2 on Friday July 10, 2020 @08:56PM (#23798410)
The 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/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

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.)

Re:Hindley-Milner Type Inference (2012) by zenhack on Friday July 10, 2020 @11:33PM (#23799232)
I assume aweinstock was referring to the first link you posted:

https://hackage.haskell.org/package/dynamic

Which is an entirely different package, and the relevant types are entirely different. Only the name is the same. The `dynamic` package does indeed appear to be an april fools joke.

The Dynamic type in base is about runtime reflection, which is occasionally useful but not something that comes up often and not really about rapid prototyping.

Re:Hindley-Milner Type Inference (2012) by frank2 on Friday July 10, 2020 @11:51PM (#23799308)
I didn't notice they were different packages.

>The Dynamic type in base is about runtime reflection, which is occasionally useful but not something that comes up often

It is not something that comes up often, but since I am used to languages like Javascript or Scheme, when it does come up, figuring out how to do it in Haskell, e.g., satisfying the monomorphic restriction, has occasionally diverted my focus away from the problem to be solved for hours while I learn more about Haskell's type system.

But yeah, what I just wrote is in no way inconsistent with the comment I initially replied to, namely,

https://news.ycombinator.com/item?id=23795687

so I am going to admit that my comments in this thread have not exactly improved the level of discourse.