Note that there are some explanatory texts on larger screens.

plurals
  1. POType provider and static argument in F#
    text
    copied!<p>I have a library, Library_1, which compiles correctly and defines a provided type :</p> <pre><code>type modelforexcel = FSharpx.ExcelFile&lt;@"template.xls", "Brokernet", true&gt; </code></pre> <p>When I include this library in another project, Library_2, the compiler complains that it can't find any "Brokernet.template.xls", at the root of the <strong>new</strong> Library_2 project.</p> <pre><code>Error 4 'C:\Library_2\template.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct. </code></pre> <p>I would like the type to refer to the original "Brokernet.template.xls", so I am trying to provide the complete path to it, but </p> <pre><code>type modelforexcel = FSharpx.ExcelFile&lt;__SOURCE_DIRECTORY__+@"Brokernet.template.xls", "Brokernet", true&gt; </code></pre> <p>does not work, as I guess it is not a literal (?) But 'obviously' defining this literal does not work either</p> <pre><code>[&lt;Literal&gt;] let a = __SOURCE_DIRECTORY__+@"Brokernet.template.xls" </code></pre> <p>Are there any way to define such a 'dynamic literal' ?</p> <p><strong>edit</strong></p> <p>Interestingly enough, if I define my type inside a module in the first library</p> <pre><code>module Load = [&lt;Literal&gt;] let a = @"Brokernet.template.xls" type modelforexcel = FSharpx.ExcelFile&lt; a , "Brokernet", true&gt; </code></pre> <p>Then the type is not 'regenerated' upon using the first library in the second one, and the type provider does not complain about the file being absent of the root of the 2nd library.</p> <p>This sheds profound insights in the compilation model of F# that are probably best exposed by masters. I'd just say, as a rough man, that "the code is in modules" </p> <p><em>PS : I guess thats one more problem which would be solved by a proper staged compilation.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload