Taking type inference to next level : Variable without declaration #1289
Replies: 3 comments 4 replies
-
Have fun with typos and easy-to-make bugs |
Beta Was this translation helpful? Give feedback.
-
First of all, thank you for the idea presented here. It may be that it seems a little immature and that the sense and purpose are not really clear. I say: Never mind! It is only an idea and I consider it legitimate to put it up for discussion. One way is to accept such things as a thought experiment without judging it right away. I try it once: I can just as well imagine (as @Happypig375 has already mentioned) that there will be a problem with practicability, since any typo of an identifier would automatically turn into the shown kind of "later-scoped-identifiers". This could be countered by the programmer expressing his intention that it is something "late-scoped". As an example, I define a syntax, namely a module A =
let inline names = &xs |> List.map (fun x -> x.Name) |> String.concat ", " In the example
Type inference would have to be structural for such "late-scoped" expressions and would have to be "parcial", because in the end it can only be solved if the whole expression is actually used. Usage and inlining: As I understand the idea, it goes like this, "There is a piece of code that is incompletely described with respect to the identifiers that are in scope, which can only gain completeness when it is used". Is that roughly how it is meant? If it is meant that way, such pieces of code that have a template character would have to be instantiated by inlining. Example: module B =
type Person = { name: string; age: int }
let xs =
[
{ name = "Josef"; age = 55 }
{ name = "Harald"; age = 61 }
]
// `A.names` is basically a template that (finally) gets instanciated by inlining
let personNames = A.names As I said, whether this is a "good" or "bad" thing, I haven't thought about it. It certainly seems a bit "exotic" to me, and I have a hard time imagining it fitting the explicitness and clarity of F#. Still, I'm not sure if there might be domain-specific languages that would be more expressive of such a concept. It's certainly interesting to see what tooling could be provided to make features of this sort more usable by the user. Personally and generally, I like the idea of a language that relies heavily on structural constraints and keeps multiple inference solutions open as long as possible, but communicates this to the user through tooling (and also makes it's final decisions clear by communicating language/type inference to the user through good tooling). Have a nice evening, and thanks again. |
Beta Was this translation helpful? Give feedback.
-
I would be happy to entertain again and again, because the conversations are interesting
I shall be starting by saying imagine :
It means, despite I had never declared a variable named Another point I can make is, inferring types based on usage would let us provide parameter names in function without saying its type explicitly like in C#, randChar would be constrained by its usage when you pass it to some function, which ultimately determines its actual type if there's multiple qualifying types which implements it can let people write shorter code, it can let people potentially reuse variable names :
Also the idea is everything is code even typos and gibberish is appealing too, basically :
this is a valid program |
Beta Was this translation helpful? Give feedback.
-
Let variables be usable without being declared
Consider
what if we can use x without declaring x, what if we can use y without declaring y, imagine
it's possible, if a variable has not been declare before then you can use it as if it's already declared, and if a variable should refer to a mutable object you have to do that manually, otherwise if you already created something immutable, the variable you just used directly represents all the stuffs you created previously, referencing to those immutable objects, giving people a good experience in the editor too by letting intellisense to look at what's available after '.'
Beta Was this translation helpful? Give feedback.
All reactions