<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <title></title>
  </head>

  <body>
    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>
          &#160;&#160; &#160;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>
            &#160;&#160; &#160;Couldn&#39;t match expected type `a&#39; against inferred type `a1&#39;
          </div>

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

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

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

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

          <div>
            &#160;&#160; &#160;In the expression: x
          </div>

          <div>
            &#160;&#160; &#160;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>
  </body>
</html>