Dependent Types

Simon Marlow simonmar@microsoft.com
Mon, 13 May 2002 17:39:05 +0100


> However, if I now comment out the functional dependency
>=20
> class Encode a b {- | a -> b -} where
>    encode :: a -> b
>=20
> and include the expressions
>=20
> x =3D encode TimeExceeded ExcTTL
>=20
> main =3D putStrLn x
>=20
> then Hugs complains
>=20
> ERROR "codes.hs" (line 37): Unresolved top-level overloading
> *** Binding             : x
> *** Outstanding context : Encode TimeExceeded=20
> (ICMPCodeTimeExceeded -> b)
>=20
> whereas GHC doesn't complain.
>=20
> Which is right?

I think you're running into a well-known(*) problem with Hugs's
implementation of the monomorphism restriction.  According to the
Haskell report, as long as a restricted binding is used monomorphically
in the body of the module, it is ok.  In this case, the constraint
'Encode TimeExceeded (ICMPCodeTimeExceeded -> b)' is resolved by the use
of 'x' in the declaration for 'main', which forces the type variable b
to String.

Hugs applies the monomorphism restriction at the binding site, and
complains if the binding isn't monomorphic without checking the rest of
the module.  It also applies defaulting at this point, which means that

	f =3D (+42)
	main =3D print (f 3 :: Int)

also elicits an error in Hugs, but not in GHC.

(*) actually I thought this was a well-known problem, but it doesn't
seem to be mentioned in the Hugs documentation as far as I can see.

Cheers,=09
	Simon