Proposed change to Dynamic library: mark it unsafe
Simon Marlow
simonmar@microsoft.com
Tue, 21 Aug 2001 09:41:46 +0100
> Proposal:
>=20
> Replace the class:
>=20
> class Typeable a where typeOf :: a -> Type
>=20
> with:
>=20
> typeOf :: Typeable a =3D> a -> Type
> typeOf =3D unsafeTypeOf
>=20
> class Typeable a where unsafeTypeOf :: a -> Type
>=20
> All existing calls of typeOf should be left as they are.
> All existing instance declarations should be changed to define
> unsafeTypeOf instead.
Hmmm. I normally associate something called 'unsafeBlah' with being
unsafe to use, not unsafe to define, so this seems a little odd. But I
don't have any better suggestions, and I agree that there ought to be at
least some indication that there's potential unsafety here.
> We also need to clarify the rules for writing correct definitions. =20
> I propose the following concise (but non-constructive) rules:
>=20
> 1) New instances must preserve the invariant that for all values x and
> y with monomorphic types,
>=20
> typeOf x =3D=3D typeOf y iff x and y have the same type.
>=20
> It is not sufficient for the types of x and y to have the same
> representation or to be isomorphic - they have to be considered
> identical by the Haskell type system. [This last sentence is
> redundant but may be helpful.]
> =20
> 2) For any (possibly bottom) value x whose type is an instance of
> Typeable,
> =20
> typeOf x /=3D _|_ and does not raise an exception
> =20
> Examples of valid and invalid definitions would also be useful.
Fully agree. The documentation is in CVS and you have commit access, I
believe :-) (at least for the old libs, I haven't brought any docs
across to the new libraries yet).
Cheers,
Simon