RE: functional dependency problem

| info :: (Collects e ce, Show e) => ce -> String | info v = show ((one v) ::e) As the error message says, and as the Haskell report says, this means info v = 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 quantified at the signature (hence the forall). 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. 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] | Sent: 08 July 2002 17:54 | To: glasgow-haskell-users@haskell.org | Subject: functional dependency problem | | | Hi, | | please consider the following example (from Mark P. Jones: | "Type Classes with Functional Dependencies" LNCS 1782, ESOP | 2000), that I've extended with a function "one": | | 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 | | The following function was ok for GHC version 5.02.3: | | info :: (Collects e ce, Show e) => ce -> String | info v = show (one v) | | However, when I tried to mention the element type "e", that | does not occurr in the result type, I got the following error | for "show ((one | v)::e)": | | 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)' | | (It did also not help to write "show ((one v)::Collects e ce => e)" | | Because "ce" determines the type "e" via the functional | dependency in "Collects", I think "e" should not be | changed/generalized to "forall e. e". (You may think, that | "e" should not be mentioned at all, if it is not part of the | functionality.) | | At least the behaviour of GHC seems to be inkonsistent, as it | should be possible to supply type signatures to (sub-)expressions. | | Regards Christian | | P.S. | duplicate "the"-typo in: | Add (Collects e ce) to the the type signature of an expression | ^^^^^^^ | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-| haskell-users |

Simon Peyton-Jones wrote:
| info :: (Collects e ce, Show e) => ce -> String | info v = show ((one v) ::e)
As the error message says, and as the Haskell report says, this means
info v = show ((one v) :: (forall e.e))
which is not what you meant.
Ok, I did not know that I have to mention a type variable in the pattern on the lhs in order to use it monomorphically on the rhs, like in: info (v :: ce) = show (one (v :: ce)) Still, I would like to get "e" as a monomorphic type from the functional dependency "ce -> e" in class Collects, maybe as a language extension in the form of: info (v :: ce | ce -> e) = show ((one v) :: e) Cheers Christian
participants (2)
-
Christian Maeder
-
Simon Peyton-Jones