Collect TypeProvider ProvidedMethod argument values in list












1














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.









share|improve this question


















  • 2




    A related question: stackoverflow.com/questions/43455091/…
    – jpe
    Dec 27 '18 at 8:09
















1














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.









share|improve this question


















  • 2




    A related question: stackoverflow.com/questions/43455091/…
    – jpe
    Dec 27 '18 at 8:09














1












1








1







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.









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












2 Answers
2






active

oldest

votes


















2














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 @@>





share|improve this answer































    1














    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)
    @@>))





    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      2














      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 @@>





      share|improve this answer




























        2














        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 @@>





        share|improve this answer


























          2












          2








          2






          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 @@>





          share|improve this answer














          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 @@>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 27 '18 at 15:04

























          answered Dec 27 '18 at 7:13









          nilekirk

          37634




          37634

























              1














              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)
              @@>))





              share|improve this answer




























                1














                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)
                @@>))





                share|improve this answer


























                  1












                  1








                  1






                  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)
                  @@>))





                  share|improve this answer














                  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)
                  @@>))






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 27 '18 at 15:41

























                  answered Dec 27 '18 at 10:12









                  demonno

                  355311




                  355311






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas