fsharp / fsharp/fslang-suggestions
Allow type providers to generate types from other types [ RFC FS-1023 ]
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
**Submitted by Tracy on 3/24/2014 12:00:00 AM**
**116 votes on UserVoice prior to migration**
* [X] [RFC Added](https://github.com/fsharp/fslang-design/blob/main/RFCs/FS-1023-type-providers-generate-types-from-types.md)
There are occasions where it would be extremely useful to generate types from other types.
As an example, F# interop with NHibernate is very clumsy simply because it's difficult to express types of the sort:
``` fsharp
// C# record class
public class MyRecord
{
public virtual int Id { get; set; }
public virtual string Description { get; set; }
// etc...
}
```
It would be very compelling to be able to represent these as F# record types, but the CIL code generated for F# records is incompatible with NHibernate.
Perhaps it could be possible, using a type provider, to generate the POCO class above from an F# record type of the sort:
```
type MyRecord = { Id : int, Description : string }
```
The type could be generated as shown below:
```
type MyPocoRecord = PocoTypeProvider()
```
I understand the difficulty of doing this at compile type.Tomas P actually explained why in a forum post (that I can't seem to find.) However, this sort of problem is the reason by the CLIMutable attribute was created, which as far as I can tell, was hard-coded directly into the F# compiler. I can see these interop dilemmas becoming more common as F# adoption increases, especially in the enterprise where tools like NHibernate are in widespread use. There ought to be a way to address them without creating one-off CLIMutable-esque attributes per se.
The feature itself would open the door to incredibly powerful metaprogramming opportunities.
## Response
*\* by fslang-admin on 6/24/2016 12:00:00 AM **
Marking this as “approved in principle” per comment below.
However it will be a difficult feature to land in practice and will be subject to very many caveats and likely limitations. There’s no certainty that this will make it into F#.
We will open an RFC for it eventually (it won’t be fast :) )
https://github.com/fsharp/FSharpLangDesign/tree/master/RFCs
Don Syme
F# Language Evolution
**[Original UserVoice Submission](https://fslang.uservoice.com/forums/245727-f-language/suggestions/5675977)**
[Archived Uservoice Comments](../tree/master/archive/suggestion-5675977-allow-type-providers-to-generate-types-from-other.md#comments)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked RFC at RFCs/FS-1023-type-providers-generate-types-from-types.md, which contains the later design for generating types from other types. Use the F# record and NHibernate POCO examples in this issue to understand the intended outcome; done would require an accepted implementation with tests, but no implementation files or tests are named here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100