Superclass Defaults

Dylan Thurston dpt@math.harvard.edu
Mon, 21 Jul 2003 15:31:02 -0400


--5UGlQXeG3ziZS81+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 21, 2003 at 06:21:33AM -0700, Ashley Yakeley wrote:
> Well I don't doubt this would be a very useful extension to the Haskell=
=20
> language: indeed it would eliminate code in all my Haskell projects. But=
=20
> before we can propose this, we have to work out what the syntax would=20
> look like. Here are some properties I think such a mechanism should have:
>=20
>   1. It should be possible to declare types as instances of
>      Monad and Functor with a different definition of fmap
>      overriding the default.
>=20
>   2. It should be possible to declare another subclass of
>      Functor that also has a default for fmap.
>=20
>   3. The members of any existing class should be=20
>      subclass-defaultable in another module; i.e., no special
>      syntax should be involved in the class declaration of
>      the superclass.
>=20
>   4. It should be possible to distinguish between different
>      appearances of the same class in the superclass context.
>      For instance:
>=20
>      class C a where
>         c :: Int -> a
>=20
>      class (C a,C b,C (a -> b)) =3D> D a b where
>         ...

I agree with all these desiderata.

I don't think any new syntax is necessarily needed.  With regards to
point 4, note that just giving a type signature is guaranteed to be
enough to tell you _which_ instance of class C you are referring to.

I think there are likely to be subtle semantic issues, however.  Also,
it seems strange to have default methods in class declarations if you
don't also allow such declarations in instance declarations.

Peace,
	Dylan


--5UGlQXeG3ziZS81+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/HD92Veybfhaa3tcRAlZnAJ9d86PnLJf76XbnnOpCZCXDSNlhSwCeLUQF
NI4wwkozdSILstSLGAfWgX8=
=/Art
-----END PGP SIGNATURE-----

--5UGlQXeG3ziZS81+--