existential typing question

Dean Herington heringto@cs.unc.edu
Mon, 27 Jan 2003 01:08:01 -0500 (EST)


Can someone explain why the type declaration for `g` is required in the
following?


class RT r t where rt :: r -> t

data D t = Dt t | forall r. RT r t => Dr r

f :: D t -> D t
f = g
 where -- g :: D t -> D t
       g (Dr r) = Dt (rt r)


As given above, the program evokes these error messages:

with GHC 5.04.2:
Bug4.hs:10:
    Could not deduce (RT r t1) from the context (RT r t)
    Probable fix:
        Add (RT r t1) to the existential context of a data constructor
    arising from use of `rt' at Bug4.hs:10
    In the first argument of `Dt', namely `(rt r)'
    In the definition of `g': Dt (rt r)

with Hugs:
ERROR "Bug4.hs":6 - Cannot justify constraints in explicitly typed
binding
*** Expression    : f
*** Type          : D a -> D a
*** Given context : ()
*** Constraints   : RT _6 a


-- Dean