When I tried to get the type providers to generate more idiomatic code, I started looking for returned currency functions from the provider.
This small piece of code:
let lambdaTest () =
let inner =
<@ fun myInt ->
fun int2 -> sprintf "A string! %d %d" myInt int2 @>
let innerType = inner.GetType()
ProvidedProperty(
"lambda",
innerType.GenericTypeArguments.[0],
IsStatic = true,
GetterCode = fun _ -> inner.Raw)
It seems that I need to work to provide int -> int -> stringif I know the signature in advance; but ideally, I would like to dynamically build nested lambda functions, something like this:
let rec inline curry<'a> format (func: Quotations.Expr<'a>) : Quotations.Expr<'a> =
match format with
| FString f ->
curry<string -> 'a> f <@ fun (s : str) -> %func @>
| FInt f ->
curry<int -> 'a> f <@ fun (i: int) -> %func @>
| Other (_, f) ->
curry<'a> f func
| End ->
func
Unfortunately, the above is not a valid F # code due to conflicting types of returned quotes.
Does anyone know if there is a way to do this?
mavnn source
share