Collect TypeProvider ProvidedMethod argument values in list
Here is a simplified snippet of the Provided method which accepts variable number of arguments, in this case 3
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
<@@
let dim1 : string = %%args.[0] : string
let dim2 : string = %%args.[1] : string
let dim3 : string = %%args.[2] : string
// let dims = [for %%arg in args do yield (arg : string) ]// [1] error below
// let dims = [for arg in args do yield (%%arg : string) ]// [2] error below
let dims = [ dim1; dim2; dim3 ] //this works
String.Join("--", dims)
@@>))
I want to collect all arguments in a single list.
What I've tried and did not work is commented in code quotation.
[1]: [FS0010] Unexpected prefix operator in expression
[FS0594] Identifier expected
[2]: [FS0446] The variable 'arg' is bound in a quotation but is used as part of a spliced expression. This is not permitted since it may escape its scope.
f# type-providers fsharp.data.typeproviders
add a comment |
Here is a simplified snippet of the Provided method which accepts variable number of arguments, in this case 3
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
<@@
let dim1 : string = %%args.[0] : string
let dim2 : string = %%args.[1] : string
let dim3 : string = %%args.[2] : string
// let dims = [for %%arg in args do yield (arg : string) ]// [1] error below
// let dims = [for arg in args do yield (%%arg : string) ]// [2] error below
let dims = [ dim1; dim2; dim3 ] //this works
String.Join("--", dims)
@@>))
I want to collect all arguments in a single list.
What I've tried and did not work is commented in code quotation.
[1]: [FS0010] Unexpected prefix operator in expression
[FS0594] Identifier expected
[2]: [FS0446] The variable 'arg' is bound in a quotation but is used as part of a spliced expression. This is not permitted since it may escape its scope.
f# type-providers fsharp.data.typeproviders
2
A related question: stackoverflow.com/questions/43455091/…
– jpe
Dec 27 '18 at 8:09
add a comment |
Here is a simplified snippet of the Provided method which accepts variable number of arguments, in this case 3
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
<@@
let dim1 : string = %%args.[0] : string
let dim2 : string = %%args.[1] : string
let dim3 : string = %%args.[2] : string
// let dims = [for %%arg in args do yield (arg : string) ]// [1] error below
// let dims = [for arg in args do yield (%%arg : string) ]// [2] error below
let dims = [ dim1; dim2; dim3 ] //this works
String.Join("--", dims)
@@>))
I want to collect all arguments in a single list.
What I've tried and did not work is commented in code quotation.
[1]: [FS0010] Unexpected prefix operator in expression
[FS0594] Identifier expected
[2]: [FS0446] The variable 'arg' is bound in a quotation but is used as part of a spliced expression. This is not permitted since it may escape its scope.
f# type-providers fsharp.data.typeproviders
Here is a simplified snippet of the Provided method which accepts variable number of arguments, in this case 3
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
<@@
let dim1 : string = %%args.[0] : string
let dim2 : string = %%args.[1] : string
let dim3 : string = %%args.[2] : string
// let dims = [for %%arg in args do yield (arg : string) ]// [1] error below
// let dims = [for arg in args do yield (%%arg : string) ]// [2] error below
let dims = [ dim1; dim2; dim3 ] //this works
String.Join("--", dims)
@@>))
I want to collect all arguments in a single list.
What I've tried and did not work is commented in code quotation.
[1]: [FS0010] Unexpected prefix operator in expression
[FS0594] Identifier expected
[2]: [FS0446] The variable 'arg' is bound in a quotation but is used as part of a spliced expression. This is not permitted since it may escape its scope.
f# type-providers fsharp.data.typeproviders
f# type-providers fsharp.data.typeproviders
asked Dec 26 '18 at 23:15
demonno
355311
355311
2
A related question: stackoverflow.com/questions/43455091/…
– jpe
Dec 27 '18 at 8:09
add a comment |
2
A related question: stackoverflow.com/questions/43455091/…
– jpe
Dec 27 '18 at 8:09
2
2
A related question: stackoverflow.com/questions/43455091/…
– jpe
Dec 27 '18 at 8:09
A related question: stackoverflow.com/questions/43455091/…
– jpe
Dec 27 '18 at 8:09
add a comment |
2 Answers
2
active
oldest
votes
Hacking your solution in the following way actually compiles
InvokeCode = (fun args ->
let dims: string = Array.zeroCreate args.Length
let mutable i = 0
let inc () = i <- i + 1
<@@
while i < args.Length do
dims.[i] <- %%args.[i]
inc ()
String.Join("--", dims)
@@>
But I suspect that you rather want to transform a Quotations.Expr
of the shape [|Value ("a"); Value ("b"); Value ("c")|]
into a single Quotations.Expr
.
You can use the patterns in Microsoft.FSharp.Quotations.Patterns
to extract stuff from the expressions in the following way
InvokeCode = (fun args ->
let dims =
args
|> Array.choose (function | Value(value, _) -> value |> string |> Some | _ -> None)
|> fun arr -> String.Join("--", arr)
<@@ dims @@>
add a comment |
This kind of solution also worked based on the answer suggested in comments: F# Type Provider development: When providing a method, how to access parameters of variable number and type?
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
let dims = List.fold ( fun state e -> <@@ (%%string)::%%state @@>) <@@ :List<string> @@> args
<@@
String.Join("--", dims)
@@>))
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53938137%2fcollect-typeprovider-providedmethod-argument-values-in-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Hacking your solution in the following way actually compiles
InvokeCode = (fun args ->
let dims: string = Array.zeroCreate args.Length
let mutable i = 0
let inc () = i <- i + 1
<@@
while i < args.Length do
dims.[i] <- %%args.[i]
inc ()
String.Join("--", dims)
@@>
But I suspect that you rather want to transform a Quotations.Expr
of the shape [|Value ("a"); Value ("b"); Value ("c")|]
into a single Quotations.Expr
.
You can use the patterns in Microsoft.FSharp.Quotations.Patterns
to extract stuff from the expressions in the following way
InvokeCode = (fun args ->
let dims =
args
|> Array.choose (function | Value(value, _) -> value |> string |> Some | _ -> None)
|> fun arr -> String.Join("--", arr)
<@@ dims @@>
add a comment |
Hacking your solution in the following way actually compiles
InvokeCode = (fun args ->
let dims: string = Array.zeroCreate args.Length
let mutable i = 0
let inc () = i <- i + 1
<@@
while i < args.Length do
dims.[i] <- %%args.[i]
inc ()
String.Join("--", dims)
@@>
But I suspect that you rather want to transform a Quotations.Expr
of the shape [|Value ("a"); Value ("b"); Value ("c")|]
into a single Quotations.Expr
.
You can use the patterns in Microsoft.FSharp.Quotations.Patterns
to extract stuff from the expressions in the following way
InvokeCode = (fun args ->
let dims =
args
|> Array.choose (function | Value(value, _) -> value |> string |> Some | _ -> None)
|> fun arr -> String.Join("--", arr)
<@@ dims @@>
add a comment |
Hacking your solution in the following way actually compiles
InvokeCode = (fun args ->
let dims: string = Array.zeroCreate args.Length
let mutable i = 0
let inc () = i <- i + 1
<@@
while i < args.Length do
dims.[i] <- %%args.[i]
inc ()
String.Join("--", dims)
@@>
But I suspect that you rather want to transform a Quotations.Expr
of the shape [|Value ("a"); Value ("b"); Value ("c")|]
into a single Quotations.Expr
.
You can use the patterns in Microsoft.FSharp.Quotations.Patterns
to extract stuff from the expressions in the following way
InvokeCode = (fun args ->
let dims =
args
|> Array.choose (function | Value(value, _) -> value |> string |> Some | _ -> None)
|> fun arr -> String.Join("--", arr)
<@@ dims @@>
Hacking your solution in the following way actually compiles
InvokeCode = (fun args ->
let dims: string = Array.zeroCreate args.Length
let mutable i = 0
let inc () = i <- i + 1
<@@
while i < args.Length do
dims.[i] <- %%args.[i]
inc ()
String.Join("--", dims)
@@>
But I suspect that you rather want to transform a Quotations.Expr
of the shape [|Value ("a"); Value ("b"); Value ("c")|]
into a single Quotations.Expr
.
You can use the patterns in Microsoft.FSharp.Quotations.Patterns
to extract stuff from the expressions in the following way
InvokeCode = (fun args ->
let dims =
args
|> Array.choose (function | Value(value, _) -> value |> string |> Some | _ -> None)
|> fun arr -> String.Join("--", arr)
<@@ dims @@>
edited Dec 27 '18 at 15:04
answered Dec 27 '18 at 7:13
nilekirk
37634
37634
add a comment |
add a comment |
This kind of solution also worked based on the answer suggested in comments: F# Type Provider development: When providing a method, how to access parameters of variable number and type?
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
let dims = List.fold ( fun state e -> <@@ (%%string)::%%state @@>) <@@ :List<string> @@> args
<@@
String.Join("--", dims)
@@>))
add a comment |
This kind of solution also worked based on the answer suggested in comments: F# Type Provider development: When providing a method, how to access parameters of variable number and type?
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
let dims = List.fold ( fun state e -> <@@ (%%string)::%%state @@>) <@@ :List<string> @@> args
<@@
String.Join("--", dims)
@@>))
add a comment |
This kind of solution also worked based on the answer suggested in comments: F# Type Provider development: When providing a method, how to access parameters of variable number and type?
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
let dims = List.fold ( fun state e -> <@@ (%%string)::%%state @@>) <@@ :List<string> @@> args
<@@
String.Join("--", dims)
@@>))
This kind of solution also worked based on the answer suggested in comments: F# Type Provider development: When providing a method, how to access parameters of variable number and type?
ProvidedMethod(methodName = "GetContext",
parameters = [ for i in [ 1..3 ] do
yield ProvidedParameter("Param" + string i, typeof<string>) ],
IsStaticMethod = true, returnType = typeof<string>,
InvokeCode = (fun args ->
let dims = List.fold ( fun state e -> <@@ (%%string)::%%state @@>) <@@ :List<string> @@> args
<@@
String.Join("--", dims)
@@>))
edited Dec 27 '18 at 15:41
answered Dec 27 '18 at 10:12
demonno
355311
355311
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53938137%2fcollect-typeprovider-providedmethod-argument-values-in-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
A related question: stackoverflow.com/questions/43455091/…
– jpe
Dec 27 '18 at 8:09