/FSharp.TypeProviders.SDK

The SDK for creating F# type providers

Primary LanguageF#OtherNOASSERTION

Issue Stats Issue Stats

F# Type Provider SDK NuGet Status

The F# Type Provider SDK is two things:

  1. The ProvidedTypes.fs API files you need to author type providers

  2. Documentation and samples on type provider creation

This package is actively seeking contributions. We are aiming for documentation (the plan is a GitHub page setup similar to FSharp.Data) with examples of all the most common features of Type Providers that people will want to use (basic erased type generation, parameterized providers, full generated types, seperating design and runtime how's and why's, etc). It will also become the main place for improvements and additions to the ProvidedTypes code.

Build status

Build status (Windows) Build Status (MacOS, mono)

The ProvidedTypes API - Adding the Files

Building a type provider nearly always starts with adding these files to your project:

  • ProvidedTypes.fsi
  • ProvidedTypes.fs

The SDK NuGet package contains both these files as well as a set of debugging helpers, and when you install it, it should add them all to your F# project. It's probably best not to modify the files after adding them as upgrades to the package will ask to replace the previous versions - either submit changes back to this project or shadow the relevant functions in a seperate file.

If using Paket, you can also add code files by direct GitHub references like this and reference the files in a project file like this.

Type providers may be used in projects that generate .NET Standard code or target other .NET Frameworks than that being used to execute the F# compiler.

The ProvidedTypes API - A Basic Type Provider

Here is a basic erasing type provider using the Provided Types API:

open ProviderImplementation
open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open System.Reflection

[<TypeProvider>]
type BasicProvider (config : TypeProviderConfig) as this =
    inherit TypeProviderForNamespaces (config)

    let ns = "StaticProperty.Provided"
    let asm = Assembly.GetExecutingAssembly()

    let createTypes () =
        let myType = ProvidedTypeDefinition(asm, ns, "MyType", Some typeof<obj>)
        let myProp = ProvidedProperty("MyProperty", typeof<string>, isStatic = true, getterCode = (fun args -> <@@ "Hello world" @@>))
        myType.AddMember(myProp)
        [myType]

    do
        this.AddNamespace(ns, createTypes())

[<assembly:TypeProviderAssembly>]
do ()

Resources

For advice on how to get started building a type provider, check out:

Support and community

Building

Use

build.sh RunTests

or

build.cmd RunTests

Library license

The library is available under Apache 2.0. For more information see the License file in the GitHub repository.

Maintainer(s)

The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)