You can&#39;t. The type can&#39;t be known, unfortunately.<div><br></div><div>With a wrapper like that you typically turn on rank-2 polymorphism and apply a function to the value directly:</div><div><br></div><div>withBar :: Bar -&gt; (forall a. BarLike a =&gt; a -&gt; r) -&gt;r</div>
<div>withBar (Bar x) = f x</div><div><br></div><div>Hope this helps,</div><div>Dan</div><div><br><div class="gmail_quote">On Sat, Dec 26, 2009 at 9:58 AM, <a href="mailto:haskell@kudling.de">haskell@kudling.de</a> <span dir="ltr">&lt;<a href="mailto:haskell@kudling.de">haskell@kudling.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


  
    
    
  

  <div>
    Hi, 

    <div>
      <br>
    </div>

    <div>
      while this works:
    </div>

    <div>
      <br>
    </div>

    <div>
      <br>
    </div>

    <div>
      <div>
        data Foo a = Foo a
      </div>

      <div>
        <br>
      </div>

      <div>
        unwrapFoo :: Foo a -&gt; a
      </div>

      <div>
        unwrapFoo (Foo x) = x
      </div>

      <div>
        <br>
      </div>

      <div>
        <br>
      </div>

      <div>
        this:
      </div>

      <div>
        <br>
      </div>

      <div>
        <br>
      </div>

      <div>
        {-# LANGUAGE ExistentialQuantification #-}
      </div>

      <div>
        <br>
      </div>

      <div>
        <div>
          class BarLike a where
        </div>

        <div>
              doSomething :: a -&gt; Double
        </div>
      </div>

      <div>
        <br>
      </div>

      <div>
        <div>
          data Bar = forall a. BarLike a =&gt; Bar a
        </div>

        <div>
          <br>
        </div>

        <div>
          unwrapBar :: Bar -&gt; a
        </div>

        <div>
          unwrapBar (Bar x) = x
        </div>

        <div>
          <br>
        </div>

        <div>
          <br>
        </div>

        <div>
          gives me:
        </div>

        <div>
          <br>
        </div>

        <div>
          <br>
        </div>

        <div>
          <div>
                Couldn&#39;t match expected type `a&#39; against inferred type `a1&#39;
          </div>

          <div>
                  `a&#39; is a rigid type variable bound by
          </div>

          <div>
                      the type signature for `unwrapBar&#39; at test.hs:8:20
          </div>

          <div>
                  `a1&#39; is a rigid type variable bound by
          </div>

          <div>
                       the constructor `Bar&#39; at test.hs:9:11
          </div>

          <div>
                In the expression: x
          </div>

          <div>
                In the definition of `unwrapBar&#39;: unwrapBar (Bar x) = x
          </div>

          <div>
            <br>
          </div>
        </div>

        <div>
          <div>
            <br>
          </div>

          <div>
            How can i deconstruct the enclosed value of type a?
          </div>

          <div>
            <br>
          </div>

          <div>
            Thanks,
          </div>

          <div>
            Lenny
          </div>
        </div>
      </div>
    </div>
  </div>

<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>