You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use type inference from with get() for to help infer set value
I propose we use type inference for a property getter and use it to help infer its matching setter value.
It would allow the StructureType, in the following simplistic example, to define it's get and set implementations abstractly requiring only one type hint (explicit or inferred) rather than two.
See properties DataCode and Description
namespaceDyanmicDataModelopenSystem.Collections.GenericopenSystem.Runtime.CompilerServicesmoduleDef =letdataInt:int ->unit = ignore
letdataString:string ->unit = ignore
[<AbstractClass>]typeDynamicImplementation()=letprops= Dictionary<string,obj>()member__.GetValue([<CallerMemberName>]?memberName:string):'T =letkey= memberName |> Option.defaultWith (fun()-> failwith "memberName required")letvalid,value = props.TryGetValue (key)if valid then
unbox value
else
failwith "missing value for 'memberName'"member__.SetValue(value:'T,[<CallerMemberName>]?memberName:string):unit =letkey= memberName |> Option.defaultWith (fun()-> failwith "memberName required")
props.[key]<- box value
typeStructureType()=inherit DynamicImplementation()memberthis.Definitions()=
Def.dataInt this.DataCode
Def.dataString this.Description
()memberthis.DataCodewith get()= this.GetValue ()andset value = this.SetValue value
memberthis.Descriptionwith get()= this.GetValue ()andset value = this.SetValue value
The existing way of approaching this problem in F# is to add an extra hint for the set value. As shown:
This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
This is not a breaking change to the F# language design
Since this is a compiler error currently, when it infers set value takes an object, as types don't match, I don't believe this is a breaking change.
Error FS3172 A property's getter and setter must have the same type. Property 'DataCode' has getter of type 'int' but setter of type 'obj'.
Error FS3172 A property's getter and setter must have the same type. Property 'Description' has getter of type 'string' but setter of type 'obj'.
I or my company would be willing to help implement and/or test this
The text was updated successfully, but these errors were encountered:
Use type inference from
with get()
for to help inferset value
I propose we use type inference for a property getter and use it to help infer its matching setter value.
It would allow the
StructureType
, in the following simplistic example, to define it's get and set implementations abstractly requiring only one type hint (explicit or inferred) rather than two.See properties
DataCode
andDescription
The existing way of approaching this problem in F# is to add an extra hint for the set value. As shown:
Pros and Cons
The advantages of making this adjustment to F# is not having to an add extra type hint that seems redundant.
The disadvantages of making this adjustment to F# are unknown to me.
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
S 🤷♂
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
Since this is a compiler error currently, when it infers set value takes an object, as types don't match, I don't believe this is a breaking change.
The text was updated successfully, but these errors were encountered: