title: Is it possible to implement polymorphic functions in a DSL using Free
body: <p>I am building a small DSL using Free Monads.</p>
  
  <p>I would like to be able to have polymorphic functions in my DSL.</p>
  
  <p>An example of something I would like to build is this:</p>
  
  <pre><code>{-# LANGUAGE TemplateHaskell #-}
  
  import           Control.Monad.Free.Church
  
  data Queue a = Queue a
  
  data MyDsl next =
    NewQueue (Queue a -&gt; next) |
    WriteToQueue (Queue a) a next
  
  makeFree ''MyDsl
  
  testProgram :: F MyDsl
  testProgram = do
    (intQueue :: Queue Int) &lt;- newQueue
    (charQueue :: Queue Char) &lt;- newQueue
    writeToQueue intQueue 1
    writeToQueue charQueue 'c'
  </code></pre>
  
  <p>The way I have encoded it above I get <code>Not in scope: type variable ‘a’</code>
  errors which makes sense. Is there a way to have polymorphic functions in a DSL using Free?</p>
  
  <p>For background the reason I would like to do this is so I can have a production interpreter that uses TQueue behind the scenes and a test interpreter that uses an in memory data structure for testing.</p>