Hacker News new | past | comments | ask | show | jobs | submit login

Doesn’t gleam come with a linter? If so, it’s likely that that can be enforced.



The designer of gleam is trying to make a linter unnecessary, by not having extraneous language features that need to be discouraged.

Guess it's not working 100% if someone feels this way! However, I would say that since the compiler/LSP knows the full type of every function it should be possible to have a code action that says 'annotate the type of this function for me'.


Yup that would be fine, so long as it's required to be done before you release your code. Putting return types on functions is signaling intent, much like left and right signaling on a car.

I want to know what your function COULD produce, not what it happens to produce now. Type inference can only show that in every current path you return a TYPE_X, and that works fine until one day you return an instance of its supertype TYPE_A, and now my code blows up because I misunderstood the contract. You may have always intended for it to return TYPE_A and its subtypes, but you never signaled that intent to others. This is why enforcing explicit contracts is necessary.


Well Gleam doesn't have supertypes, so the function signature (even when inferred) does describe everything your function could possibly produce. If the author changes that, your code will stop compiling, not blow up at runtime.

I agree that packages authors really should annotate their types though, and possibly that they ought to be forced to do so, just to make reading the code easier.


Gleam doesn't have subtyping, so the drawback described here is not possible.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: