As far as I know, both tools are used for code generation. Libraries generated with t4 can be used everywhere and type providers can only be used with F#, so what is the point?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As @pad said, it is possible to consume F# Type Providers from C# (depending on how you implement your type provider).
IMO, the main benefit of type providers over T4 is that they’re distributed as .NET assemblies, which makes it much easier/simpler to use them from multiple projects. AFAIK, T4 requires you to copy (or otherwise include) the macro files into each project you want to use them in. (It’s been a few years since I’ve used T4 though, so it’s possible this has changed.)
In general I think that there is a large overlap in functionality between Type Providers and T4; so yes, if you wanted, you could replicate much of the Type Provider functionality with T4. However, the more functional programming you do, the more you’ll learn that modularity — in just the right amounts — is what makes functional languages much more productive than their imperative bretheren; and for this same reason, the way Type Providers are constructed and the way they integrate with the F# compiler make them better to use in practice than T4 macros.