[Haskell-cafe] Deconstruction

Miguel Mitrofanov miguelimo38 at yandex.ru
Sat Dec 26 04:30:40 EST 2009


On 26 Dec 2009, at 11:58, haskell at kudling.de wrote:

> class BarLike a where
>     doSomething :: a -> Double
>
> data Bar = forall a. BarLike a => Bar a
>
> unwrapBar :: Bar -> a
> unwrapBar (Bar x) = x
>
> How can i deconstruct the enclosed value of type a?

You can't write a function with a type that mentions existentially  
quantified "a". Period.

But you can deconstruct the enclosed value temporarily:

getSomething :: Bar -> Double
getSomething b =
     case b of
         Bar a -> doSomething a


More information about the Haskell-Cafe mailing list