News for hackers. Stuff that matters.
Re:Dynamic type systems are not inherently more open by chongli on Sunday January 19, 2020 @09:11AM (#22091502)
This already exists in Haskell. Firstly, Haskell has type inference so you can write entire programs without any type annotations. Second of all, since type annotations actually help to document your code, it’s recommended as good Haskell style to annotate all top-level definitions.

To aid you in the latter task, you can press a key in your editor to fetch an automatically-inferred type for the name under the cursor and insert it into your code, then refine it as necessary if you find it to be too general (inference always gives the most general type possible).

Re:Dynamic type systems are not inherently more open by pron on Sunday January 19, 2020 @10:28AM (#22091892)
Type inference does not automatically "typify" your code. The type system -- whether the type annotations are explicit or the types are inferred -- determines which expressions are "well-formed" (i.e. syntactically correct), and so you can't write arbitrary code. E.g., in Haskell, you can know for a fact that at one call site a Maybe instance is Just, but whether you annotate your types or rely on inference, the type system will still force you to match on the constructor even though you don't really have to from a correctness perspective.
Re:Dynamic type systems are not inherently more open by PhineasRex on Sunday January 19, 2020 @01:01PM (#22092794)
If you're talking about the fact that you have to unbox the Maybe, that's not really related to type inference or static types but how "null" values are represented in the language.

If you're talking about exhaustiveness checks, you can disable those and use `-fdefer-type-errors` to compile programs which don't type-check.

Although I will say that most of the time when you have a Maybe instance that you know is Just, it means you're branching in the wrong part of your program.

Re:Dynamic type systems are not inherently more open by pron on Sunday January 19, 2020 @03:51PM (#22093979)
> If you're talking about exhaustiveness checks, you can disable those and use `-fdefer-type-errors` to compile programs which don't type-check.

Right, but if you were using, say, Idris, the program would type check. It's just that Haskell's type system is too weak. Disabling type checking is not what the question was about. The program is type-correct, yet not in Haskell's particular system.

> Although I will say that most of the time when you have a Maybe instance that you know is Just, it means you're branching in the wrong part of your program.

Perhaps, but that doesn't change the fact that if you write it in some way that is perfectly correct, Haskell's particular type system will still not accept your program.

Re:Dynamic type systems are not inherently more open by firethief on Sunday January 19, 2020 @01:30PM (#22092984)
If the reason you know your Maybe T is a Just _ is that you tested it locally: in any language that favors the Maybe pattern, the idiomatic way of performing that test makes the result available to the type system (destructuring / combinators / 'nads). On the other hand, if you know your Maybe is a Just because of non-local information, you will eventually turn out to be wrong :)
Re:Dynamic type systems are not inherently more open by pron on Sunday January 19, 2020 @03:49PM (#22093967)
No, you can know -- and even prove -- that at a certain callsite, a Maybe would be a Just, and if you were using a dependent type system, you can prove that in the type system (although it probably won't be automatically inferred -- you may have to work hard for the proof), but Haskell's type system is too weak to express such properties and such proofs, at least in the general case.
Re:Dynamic type systems are not inherently more open by hopia on Sunday January 19, 2020 @10:00AM (#22091740)
On what editor setup you get this kind of functionality with Haskell? I mean the auto-insert of the inferred types.
Re:Dynamic type systems are not inherently more open by chongli on Sunday January 19, 2020 @10:10AM (#22091795)
I’ve been out of the game for a number of years but I used something called ghc-mod [1] with its associated vim plugin [2] to get this functionality. Moving forward, it seems that all of the effort has moved over to Haskell IDE Engine [3]. It looks like this exact feature hasn’t been brought over yet but it is planned. In the mean time you could still use ghc-mod though.

[1] https://github.com/DanielG/ghc-mod

[2] https://github.com/eagletmt/ghcmod-vim

[3] https://github.com/haskell/haskell-ide-engine

Re:Dynamic type systems are not inherently more open by hopia on Sunday January 19, 2020 @10:19AM (#22091842)
Thanks for the tip! Haskell IDE engine is exactly what I've been using til now and would've been very pleased to find out it had such a convenient feature.

Ghcide is on my list to try next as it's gotten a lot of attention lately.

Re:Dynamic type systems are not inherently more open by jose_zap on Sunday January 19, 2020 @02:39PM (#22093469)
Yes, it already has a code command to automatically add top level type annotations. The caveat I that it can only work if you add -Wall to your compilations flags.
Re:Dynamic type systems are not inherently more open by danidiaz on Sunday January 19, 2020 @10:14AM (#22091817)
Re:Dynamic type systems are not inherently more open by hopia on Sunday January 19, 2020 @10:20AM (#22091851)
Template Haskell not working on ghcide has sadly been holding me back with it. I've heard great things about it otherwise
Re:Dynamic type systems are not inherently more open by jose_zap on Sunday January 19, 2020 @02:39PM (#22093474)
You can use HIE. It supports template Haskell
Re:Dynamic type systems are not inherently more open by pwm on Sunday January 19, 2020 @02:31PM (#22093415)
Recent ghcide can do it now as well as https://github.com/mpickering/apply-refact for hlint