<!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 -> 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 -> Double
</div>
</div>
<div>
<br />
</div>
<div>
<div>
data Bar = forall a. BarLike a => Bar a
</div>
<div>
<br />
</div>
<div>
unwrapBar :: Bar -> 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't match expected type `a' against inferred type `a1'
</div>
<div>
      `a' is a rigid type variable bound by
</div>
<div>
          the type signature for `unwrapBar' at test.hs:8:20
</div>
<div>
      `a1' is a rigid type variable bound by
</div>
<div>
           the constructor `Bar' at test.hs:9:11
</div>
<div>
    In the expression: x
</div>
<div>
    In the definition of `unwrapBar': 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>