You can't. The type can'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 -> (forall a. BarLike a => a -> r) ->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"><<a href="mailto:haskell@kudling.de">haskell@kudling.de</a>></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 -> 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>
</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>