-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit Discriminated Unions #306
Comments
There is a language suggestion regarding provided DU & records: fsharp/fslang-suggestions#154 And another one to be able to pass types to type providers: fsharp/fslang-suggestions#212 |
The main thing is that it's just a lot of work. The way TPs are architected (providing .NET System.Type/MethodInfo etc. and the compiler converts them to F# TAST nodes) effectively means we have to fully invert the compilation process from .NET IL types --> F# TAST types. This is implemented in tast.fs and infos.fs in the F# compiler for methods, types, properties, events but there is no corresponding inversion for F#-defined union/record types. The inversion would be similar to that implemented in FSharp.Reflection.FSharpType/FSharpValue based on the attributes etc. But it's painful to implement and fully test accurately.
Yes, people are interested in this |
@dsyme Thank you for the explanation (If you don't mind I have on further question). If generating TAST in F# would be simple enough, the TAST could be given straight to the Compiler, then compilation could happen as usual. Why is it the other way around (Type/MethodInfo -> TAST) ? |
The TAST is an internal compiler representation and not deemed to be sufficiently stable nor simple enough to allow direct generation. |
Thanks for the explanation, should I close this now ? |
@JaggerJo It's ok to leave it open I think |
What about providing the FSharp compiler services interface to a TypeProvider, so it can get better metadata? But FSharpCompilerServiceTypeProvider, that would be a fun thing ! |
I'm currently playing around with building a DSL for Avalonia UI. I looked at how Fabulous generates types one time.
It would be interesting to create the DSL dynamically using a (generative) type provider. In my case I would like to generate DU's for all implementations of
IControl
.This would make it extremely simple to use 3rd party controls, because bindings are generated at compile/ design time.
Currently it is (as far as I know) not possible to emit F# specific types like Records or Discriminated Unions from a Type Provider.
EDIT:
just found out there is a discussion about using a TP in Fabulous
The text was updated successfully, but these errors were encountered: