functional dependency problem

Simon Peyton-Jones simonpj@microsoft.com
Tue, 9 Jul 2002 09:16:16 +0100


| info :: (Collects e ce, Show e) =3D> ce -> String
| info v =3D show ((one v) ::e)

As the error message says, and as the Haskell report says,
this means

  info v =3D show ((one v) :: (forall e.e))

which is not what you meant.  Haskell does not have scoped
type variables, so any type variables in signatures are=20
quantified at the signature (hence the forall). =20

GHC does have scoped type variables, but in this case
since 'e' is not mentioned in the argument or result type
they are no help either.=20

So apart from the double 'the' (thank you) GHC is behaving
correctly here.

Simon

| -----Original Message-----
| From: Christian Maeder [mailto:maeder@Informatik.Uni-Bremen.DE]=20
| Sent: 08 July 2002 17:54
| To: glasgow-haskell-users@haskell.org
| Subject: functional dependency problem
|=20
|=20
| Hi,
|=20
| please consider the following example (from Mark P. Jones:=20
| "Type Classes with Functional Dependencies" LNCS 1782, ESOP=20
| 2000), that I've extended with a function "one":
|=20
| class Collects e ce | ce -> e where
|     empty  :: ce
|     insert :: e -> ce -> ce
|     member :: e -> ce -> Bool
|     one    :: ce -> e           -- added just for the sake of
| demonstration
|=20
| The following function was ok for GHC version 5.02.3:
|=20
| info :: (Collects e ce, Show e) =3D> ce -> String
| info v =3D show (one v)=20
|=20
| However, when I tried to mention the element type "e", that=20
| does not occurr in the result type, I got the following error=20
| for "show ((one
| v)::e)":
|=20
|     Could not deduce (Collects e ce) from the context ()
|     Probable fix:
|         Add (Collects e ce) to the the type signature of an expression
|     arising from use of `one' at Collects.hs:11
|     In an expression with a type signature: (one v) :: forall e. e
|     In the first argument of `show', namely `((one v) :: forall e. e)'
|=20
| (It did also not help to write "show ((one v)::Collects e ce =3D> e)"
|=20
| Because "ce" determines the type "e" via the functional=20
| dependency in "Collects", I think "e" should not be=20
| changed/generalized to "forall e. e". (You may think, that=20
| "e" should not be mentioned at all, if it is not part of the=20
| functionality.)
|=20
| At least the behaviour of GHC seems to be inkonsistent, as it=20
| should be possible to supply type signatures to (sub-)expressions.
|=20
| Regards Christian
|=20
| P.S.=20
| duplicate "the"-typo in:
|         Add (Collects e ce) to the the type signature of an expression
|                                ^^^^^^^=20
| _______________________________________________
| Glasgow-haskell-users mailing list=20
| Glasgow-haskell-users@haskell.org=20
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-users
|=20