Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate curried arguments for a ProvidedMethod?

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?

like image 574
Gustavo Guerra Avatar asked Jan 17 '26 21:01

Gustavo Guerra


1 Answers

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.

like image 90
Colin Bull Avatar answered Jan 20 '26 14:01

Colin Bull