[Haskell-cafe] Are GADTs what I need?

Chaddaï Fouché chaddai.fouche at gmail.com
Mon Jul 13 12:20:53 EDT 2009


On Mon, Jul 13, 2009 at 12:41 PM, Kev
Mahoney<maillist at kevinmahoney.co.uk> wrote:
> So far, I've learnt you can do this:
>
> data Value where
> VInt :: Integer -> Value
> ...
> VWrapper :: a -> Value
>
> which can let you encode arbitrary 'dynamic' types into Value. I was
> hoping to be able to pattern match to get the value out again e.g.

As such this type is pretty useless, since you don't know anything
about a, you can't do anything with it... Which is why you add
typeclass constraints, so you can use this value. Data.Dynamic adds a
Typeable constraint, which allows you to do safe coercing, so you can
have a "typecase", if not like you tried to do it.

-- 
Jedaï


More information about the Haskell-Cafe mailing list