[Haskell-cafe] Typeclasses and GADT [Was: Regular Expressions
without GADTs]
John Meacham
john at repetae.net
Wed Oct 26 19:58:02 EDT 2005
On Wed, Oct 26, 2005 at 01:37:29PM +0200, Tomasz Zielonka wrote:
> On 10/19/05, oleg at pobox.com <oleg at pobox.com> wrote:
> > I never argued about convenience of GADTs. They can be quite handy
> > when dealing with existentials: GADT embody a safe cast and so spare
> > us form writing the boring casting code ourselves. And perhaps this is
> > the only compelling case for GADTs.
>
> Speaking about casts, I was playing with using GADTs to create a
> non-extensible version of Data.Typeable and Data.Dynamic.
> I wonder if it's possible to write such a thing without GADTs (and
> unsafeCoerce, which is used in Data.Dynamic, IIRC).
>
> BTW, being non-extensible has some benefits, for example,
> I feel a bit uneasy when I use full blown Dynamics in Haskell
> (not that I do it that often).
>
> See code in the attachment. It has some functions which
> I didn't find in Data.Dynamics, actually one function:
> withDyn :: Dyn -> (forall a. Typed a => a -> b) -> b
perhaps something like
class Typeable a => MyTypeable a
newtype MyDynamic = MyDynamic Dynamic
instnance MyTypeable Int
instance MyTypeable Foo
(and add whatever appropriate access methods you like)
and then not export the MyTypeable class so new instances could not be
declared.
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-Cafe
mailing list