[Haskell-cafe] Are GADTs what I need?
chris at eidhof.nl
Mon Jul 13 08:09:57 EDT 2009
The types are "thrown away" during compile time. Therefore, if you
have a constructor "VWrapper :: a -> Value" nothing is known about
that "a" when you scrutinize it.
What you could do, however, is something like this:
> data Value a where
> VInt :: Integer -> Value Integer
> VWrapper :: a -> Value a
And then you can write a function doSomething:
> doSomething :: Value String -> String
> doSomething (VWrapper s) = s
On 13 jul 2009, at 12:41, Kev Mahoney wrote:
> Hi there,
> I'm currently writing an interpreter that I would like to be able to
> use with other haskell programs. I would like to be able to pass along
> arbitrary types though the interpreter. I've seen hints that GADTs can
> do this, but I am having trouble understanding them.
> 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.
> doSomething :: Value -> ....
> doSomething (VWrapper String s) = .....
> Also, anything that can help me out with GADTs in general will be much
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe