FS-1056 - Allow overloads of custom keywords in computation expressions #301
Nhowka
started this conversation in
Language and core library RFC discussions
Replies: 2 comments 7 replies
-
Would this feature help with what the LINQ query builder can do? Maybe the different functions to handle nullable value in LINQ expressions could be unified in later versions of FSharp.Core? |
Beta Was this translation helpful? Give feedback.
0 replies
-
As the builders are coming fashionable, we'd need more validation possibilities, and extending this would help. Here is a code sample that is not working in F# 5.0: type InitialState =
{ Name : string
Username : string option
}
type ValidState =
{ Name : string
Username : string
MoreData : string option
}
type MyBuilder() =
member __.Yield _ =
{ Name = ""
Username = None
} : InitialState
// This fails for custom operator overloading now:
[<CustomOperation "name">]
member __.Name(state:InitialState, name) = { state with Name = name }
member this.Name(state:ValidState, name) = { state with Name = name }
[<CustomOperation "username">]
member __.Username(state:InitialState, username) =
{ Name = state.Name
Username = username
MoreData = None
} : ValidState
let my = type MyBuilder()
let process (x:ValidState) =
//...
()
my { name "hello"; username "hello" } |> process // Valid
my { username "hello"; name "hello" } |> process // Valid
my { name "hello" } |> process // Intentionally invalid, compile time error |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
RFC here
Beta Was this translation helpful? Give feedback.
All reactions