Typeable and 'forall' in data constructors

Akos Korosmezey Akos.Korosmezey at eth.ericsson.se
Wed Apr 21 15:23:12 EDT 2004


I am tying to write a Term class with function application:

   data (Typeable a) => Term a =
       Const a |
        LVar Int |
        forall b. Typeable b => App (Term (b -> a)) (Term b) |
         Lam (Term a)                            
             
Because 'forall' is present, ghc refuses to derive Typeable and Data for 
Term. I tried to implement them:

   instance (Typeable a) => Typeable (Term a) where
       typeOf w = mkAppTy (mkTyCon "Term.Term") [typeOf (undefined :: a)]

   instance (Typeable a) => Data (Term a) where
       toConstr (Const _) = mkConstr 1 "Const" Prefix
       toConstr (LVar _) = mkConstr 3 "LVar" Prefix
       toConstr (App _ _) = mkConstr 4 "App" Prefix 
       toConstr (Lam _) = mkConstr 5 "Lam" Prefix

But ghc 6.2.1 returns with error on the line 'toConstr (App _ _)...':  
parse error on input `b'. How can this be fixed?
Thank you

Akos Korosmezey





More information about the Glasgow-haskell-users mailing list