Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FSharp ProvidedConstructor Arguments

I'm trying to implement a typeprovider using the examples I found in different places.

What I want is to be able to create a constructor which assigns the provided arguments to the right properties. The result will have do the same thing as the type below.

type SomeType(arg1: int, arg2: string) = 
    member this.Arg1 = arg1
    member this.Arg2 = arg2

I've tried different approaches, but I just can't get passed the first argument in the args list.

ProvidedConstructor(
    parameters = parameters, 
    InvokeCode = (fun args -> ??)

What kind of code must be invoked to achieve this. Or do I have to take another approach?

like image 855
BBL Avatar asked Jan 17 '26 00:01

BBL


1 Answers

What will be the underlying runtime representation of your provided type (the type you passed to the ProvidedTypeDefinition baseType argument)? The ProvidedConstructor InvokeCode is a function that takes a list of expressions and returns an expression of the underlying type. For example, if the runtime representation is a 2-element tuple, InvokeCode would be something like this:

InvokeCode = (fun [arg1;arg2] -> <@@ (%%arg1:int), (%%arg2:string) @@>)

Make sure to read this tutorial

like image 198
Gustavo Guerra Avatar answered Jan 19 '26 14:01

Gustavo Guerra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!