I want to generate a static method this the signature A -> B -> C
But I can only generate A * B -> C:
ProvidedMethod(name, [ ProvidedParameter("A", aType); ProvidedParameter("B", bType) ], cType, IsStaticMethod = true)
I can't do the currying manually, because function types don't work correctly in type providers, only delegate types. Is there any other way to do this that I'm not aware of, or is this just not supported at all?
I suspect that you can't do currying by using the ProvidedMethod simply. However you could make your methods return a function that wraps the application of the parameters.
public Func<A, Func<B, C>> Curry<A, B, C>(Func<A, B, C> func)
{
return a1 => a2 => func(a1, a2);
}
Example above given in C# to show the types more explicit, in a type provider, this will look something like the following.
let retType = typeof<('a -> ('b -> 'c)>
let ftype = typeof<('a -> 'b -> 'c>
let method = ProvidedMethod(name, [ProvidedParameter("Func", ftype)], retType)
I don't currently have an F# compiler to hand (I'm on my iPad) but, hope this is a push in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With