Allowing type variables in local values #3779
joshi-monster
started this conversation in
Ideas & suggestions
Replies: 1 comment
-
I believe there's issue for not making generic type variables in let annotations rigid, but for the life of me I can't find it now. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I'm sorry, but I'm still confused; this might also belong in questions 🙂
So from what I could figure out from probing the compiler, the following is true:
Is this the intended semantics?
If it is:
I think allowing the introduction of new type variables in (non-function) values like that is mostly useless and should produce a warning/error immediately, instead of more confusing type errors further down. Since everywhere else in the language a value of type
List(a)
can be used in places where i.e. aList(Int)
would be expected, an error saying the types here dont match was not very clear to me at first.It also allows you to accidentally change the type of local functions like in the last example, leading to some really confusing type errors; why was
fn(Int) -> a
expected here?Unfortunately I think making this an error would be a breaking change.
If it isn't:
Personally I would prefer allowing generic local bindings as well, with the only difference being that you need to annotate them locally, similarly to functions. Those should also like local functions introduce a new scope for their type variables, to avoid problems like the last example. This would remove those edge cases, making local (non-function) values behave exactly the same as all other values or functions in the language.
Also sorry again for not knowing all the right language dev terms; I hope what I mean is somewhat understandable. I only know so much from looking at Haskell from a very safe distance for a long time 😄
~ 💜
Beta Was this translation helpful? Give feedback.
All reactions