Polymorphism inside monads : <p>I'm trying to pull a value out of a monad, but keep the <em>value</em>, which doesn't depend on the monad, polymorphic. Specifically:</p>

<pre><code>foo :: (Monad mon, Ring a) =&gt; mon a
foo = return 3

main :: IO ()
main = do
  x &lt;- foo
  print (x :: Double)
  print (x :: Int)
</code></pre>

<p>The point is that the monadic portion of the computation is expensive to compute, so I only want to do it once, while keeping the value in the monad polymorphic. All of my attempts so far:</p>

<ol>
<li>giving <code>x</code> the signature <code>forall a. (Ring a) =&gt; a</code>)</li>
<li>giving <code>foo :: (Monad mon) =&gt; mon (forall a . (Ring a) =&gt; a)</code> </li>
<li>enabling <code>-XNoMonomorphismRestriction</code> and <code>NoMonoLocalBins</code> </li>
</ol>

<p>have either not worked or given errors about impredicative polymorphism, which I'm not willing to use. Is there some way to pull a polymorphic value out of a monad without impredicative polymorphism (or alternatively: is there a safe way to use impredicative polymorphism in GHC)?</p>
