question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emit Discriminated Unions

See original GitHub issue

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.

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.

  1. Why isn’t it possible to generate F# specific types (aren’t they just nested classes with custom attributes/metadata after all) ?
  2. 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:open
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Luiz-Monadcommented, Feb 5, 2020

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 !

0reactions
dsymecommented, Jul 19, 2019

@JaggerJo It’s ok to leave it open I think

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found