[Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Kev Mahoney
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

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Chris Eidhof
Hey Kev, 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 ...

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Chris Eidhof
Then you could add a specific constructor for String. The main point is: the case construct only works for values, not for types. There is no typecase construct. If you want to have certain restrictions on the 'a', such as the Show class, you could also do something like this: data Value

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Kev Mahoney
Oops, wrong mail account for my last email. Apologies. What I'm trying to accomplish is being able to write haskell libraries for the interpreter that don't use the interpreter's predefined Value types, without having to edit the Value type itself and add a new constructor (i.e. it's abstracted

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Chaddaï Fouché
On Mon, Jul 13, 2009 at 12:41 PM, Kev Mahoneymaill...@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

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Kev Mahoney
Thanks, I hadn't noticed Data.Dynamic. It never even occurred to me that something like this would be in the standard libraries. It looks like it's precisely what I was looking for, after a brief scan of the documentation. I will report back if I bump into any problems with it 2009/7/13 Chaddaï

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Ryan Ingram
On Mon, Jul 13, 2009 at 9:18 AM, Kev Mahoneymaill...@kevinmahoney.co.uk wrote: That said, I think I may defer this until I understand the ins and outs of Haskell's type system a little better. I think a parametrized type will be the only way to do it. The only reason I thought GADTs may be

Re: [Haskell-cafe] Are GADTs what I need?

2009-07-13 Thread Luke Palmer
On Mon, Jul 13, 2009 at 6:09 AM, Chris Eidhof ch...@eidhof.nl wrote: Hey Kev, 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: