title: F# Type Providers: can you use a type provider in the same project in which it is defined?
body: <p>I've followed the tutorial about F# type providers <a href="https://www.aaron-powell.com/posts/2015-02-06-writing-a-fsharp-type-provider" rel="nofollow noreferrer">there</a>, source code available <a href="https://gist.github.com/aaronpowell/74c4bc0315c2e1b42b48" rel="nofollow noreferrer">here</a>.</p>
  
  <p><code>Program.fs</code>:</p>
  
  <pre class="lang-ml prettyprint-override"><code>open System.Reflection
  open Microsoft.FSharp.Core.CompilerServices
  open ProviderImplementation.ProvidedTypes
  
  [&lt;TypeProvider&gt;]
  type StringTypeProvider(config: TypeProviderConfig) as this =
      inherit TypeProviderForNamespaces(config)
  
      let namespaceName = "Samples.StringTypeProvider"
      let thisAssembly = Assembly.GetExecutingAssembly()
  
      let staticParams = [ProvidedStaticParameter("value", typeof&lt;string&gt;)]
  
      let t = ProvidedTypeDefinition(thisAssembly, namespaceName, "StringTyped", Some typeof&lt;obj&gt;, hideObjectMethods = true)
  
      do t.DefineStaticParameters(
          parameters = staticParams,
          instantiationFunction = (fun typeName paramValues -&gt;
              match paramValues with
              | [| :? string as value |] -&gt;
                  let ty = ProvidedTypeDefinition(
                              thisAssembly,
                              namespaceName,
                              typeName,
                              Some typeof&lt;obj&gt;
                          )
  
                  let lengthProp = ProvidedProperty(
                                      "Length",
                                      typeof&lt;int&gt;,
                                      getterCode = fun _ -&gt; &lt;@@ value.Length @@&gt;
                                  )
                  ty.AddMember lengthProp
  
                  let charProps = value
                                      |&gt; Seq.map(fun c -&gt;
                                              let p = ProvidedProperty(
                                                          c.ToString(),
                                                          typeof&lt;char&gt;,
                                                          getterCode = fun _ -&gt; &lt;@@ c @@&gt;
                                                      )
                                              let doc = sprintf "The char %s" (c.ToString())
                                              p.AddXmlDoc doc
  
                                              p
                                          )
                                      |&gt; Seq.toList
                  ty.AddMembersDelayed (fun () -&gt; charProps)
  
                  let sanitized = value.Replace(" ","")
                  let valueProp = ProvidedProperty(
                                      sanitized,
                                      typeof&lt;string&gt;,
                                      getterCode = fun _ -&gt; &lt;@@ value @@&gt;
                                  )
                  valueProp.AddXmlDoc "This is the value that you gave me to start with"
                  ty.AddMember valueProp
  
                  let ctor = ProvidedConstructor(
                              parameters = [],
                              invokeCode = fun args -&gt; &lt;@@ value :&gt; obj @@&gt;
                          )
  
                  ctor.AddXmlDoc "Initializes a the awesomes"
  
                  ty.AddMember ctor
  
                  let reverser = ProvidedMethod(
                                      methodName = "Reverse",
                                      parameters = [],
                                      returnType = typeof&lt;string&gt;,
                                      invokeCode = (fun _ -&gt;
                                                      &lt;@@
                                                      value
                                                          |&gt; Seq.map (fun x -&gt; x.ToString())
                                                          |&gt; Seq.toList
                                                          |&gt; List.rev
                                                          |&gt; List.reduce (fun acc el -&gt; acc + el)
                                                      @@&gt;))
  
                  ty.AddMember reverser
  
                  ty
              | _ -&gt; failwith "No idea what you're doing"
          )
      )
  
      do this.AddNamespace(namespaceName, [t])
  [&lt;assembly:TypeProviderAssembly&gt;]
  do()
  
  open Samples.StringTypeProvider
  
  type snowman = Samples.StringTypeProvider.StringTyped&lt; @"☃" &gt;
  let doYouWantToBuildASnowman = snowman()
  doYouWantToBuildASnowman.``☃``
  
  [&lt;EntryPoint&gt;]
  let main _ =
      0
  </code></pre>
  
  <p>I have the errors below:</p>
  
  <pre><code>  &lt;FSharpPlayground&gt;\Program.fs:3819 The namespace or module 'Samples' is not defined.
    &lt;FSharpPlayground&gt;\Program.fs:3862 The namespace or module 'Samples' is not defined.
    &lt;FSharpPlayground&gt;\Program.fs:3975 The type 'Object' does not define the field, constructor or member '☃'.
  </code></pre>
  
  <p>Which makes sense but is there a workaround to be able to use the F# Type Provider defined in the same project in which it is defined? </p>
  
  <p>[EDIT 1]</p>
  
  <p>Even if I put the whole <code>StringTypeProvider</code> definition into another file with <code>namespace Samples.StringTypeProvider</code> and then import it in <code>Program.fs</code> with <code>open Samples.StringTypeProvider</code> it does not work out.</p>
  
  <p>For instance, typing <code>type snowman = Samples.StringTypeProvider.StringTyped&lt; @"☃" &gt;</code>, I'm getting:</p>
  
  <pre><code>Program.fs(3, 43): [FS0039] The type 'StringTyped' is not defined in 'Samples.StringTypeProvider'. Maybe you want one of the following:
     StringTypeProvider
  </code></pre>
  
  <p>[EDIT 2]</p>
  
  <p>I tried to separate the type provider definition and the place where it is used, but I'm still getting errors: <a href="https://github.com/ehouarn-perret/Issues.TypeProviders" rel="nofollow noreferrer">https://github.com/ehouarn-perret/Issues.TypeProviders</a> </p>