0
votes

I have F# function

generateCode params

that generates a code on F#(.fs file). And I want to write Type Provider, that runs generateCode() and gives generated functions as provided.

For example, my function generated:

module Calc

open Operations
let Calculate a b = add a b

And i want to have Type Provider that provides such functionality:

type MyType = MyTypeProvider<args>
sum = MyType.Calculate a b

UPD The main problem is to add generated code to assembly and then get function names.

1

1 Answers

5
votes

Unfortunately, creating a type provider is not that simple. Rather than generating source code, type providers need to build an implementation of a certain interface and then produce F# quotations (which is a data structure representing source code - like LINQ expression trees).

For a good tutorial on implementing type providers, see Michael Newton's Type Providers From the Ground Up and a follow up Type Providers From the First Floor.