Emit Discriminated Unions
See original GitHub issueI’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
.
type ButtonAttr =
| Name of string
| Width of float
…
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.
- Why isn’t it possible to generate F# specific types (aren’t they just nested classes with custom attributes/metadata after all) ?
- Is there a general interest in making this possible (or is it just me wanting this) ?
EDIT: just found out there is a discussion about using a TP in Fabulous
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Discriminated Unions (ONC+ Developer's Guide)
A discriminated union is a C union and an enum_t value that selects an ... and guarantees that different C compilers emit identical...
Read more >Using Reflection.Emit to generate Discriminated Unions
Basically, you're relying on the F# compiler to generate the required types. My limited understanding is that both records and discriminated ...
Read more >Discriminated Unions or Tagged Unions Types
In this article, we will cover tagged union types (AKA discriminated unions). And we have more to come, in future articles: Assertion guards;...
Read more >Discriminated Unions - F# | Microsoft Learn
Discriminated unions provide support for values that can be one of a number of named cases, possibly each with different values and types....
Read more >Understanding the discriminated union pattern
The discriminated union pattern is a way of narrowing a union type. A requirement for this pattern is for the types in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What about providing the FSharp compiler services interface to a TypeProvider, so it can get better metadata? And with ProvidedDU and ProvidedRecords, that would increase the flexibility. Perhaps we could have a DSL for creating the relevant part of the TypeProvider output that will become the
TAST
. (of course you wouldn’t expose the real TAST) I don’t mind it being internally represented by Type/MethodInfo, but wouldn’t it be simpler having a specific AST/DSL for TypeProviders ? (nothing impedes someone doing that and it creating the Quotation expressions needed, that’s precisely how I’m thinking to tackle my TypeProvider ) [edit: after reading other topics, I guess I have my historical reasons answer]But FSharpCompilerServiceTypeProvider, that would be a fun thing !
@JaggerJo It’s ok to leave it open I think