[Haskell] Could not deduce .. why ?

Marc Weber marco-oweber at gmx.de
Sun Oct 12 11:38:30 EDT 2008


Surely I've overseen a small point. But I can't see it:
Why doesn't ghc recognize taht elc_ (class decl), elc (instance decl) and elc_1 are the same type
To help you find the connecting pieces faster I've marked them with ## ##

Marc


data PT a b = PT b -- phantom type containing state a and the result b

class AddEl el_ el2_ elc_ where
  addEl :: el_ -> elc -> el2_ -- el, child
 
-- ========== adding sub elements (tags) =============================
class AddElT est el_ 
             estc ##elc_##
             est2 el2_
    | estc est -> est2
    , est est2 estc el2_ -> el_
    , est est2 estc el2_ -> elc_
    where
  addElT :: PT est el_ -> PT estc ##elc_## -> PT est2 el2_
 
-- first child ? attrs ok? 
instance (
    AddEl el el2 ##elc##           <-- this is not recognized because elc != elc_1
  , Consume st (Elem celType) st'
  , DetermineElAddEl (NYV (Element elType AttrsOk st HFalse)) el
                     (Valid celType) elc
                     (NYV (Element elType AttrsOk st' HTrue)) el2
  ) => AddElT (NYV (Element elType AttrsOk st HFalse)) el
              (Valid celType) ##elc##     <-- elc_ from class declaration
              (NYV (Element elType AttrsOk st' HTrue)) el2
              where
    addElT (PT t) (PT ##c##) = PT $ addEl t c   -- <<<<<<<<< line 435, c should have  type elc, not elc_1
 
 
src/Text/XML/Validated/Types.hs|435 col 32 error| 
||     Could not deduce (AddEl el el2 elc_1)
||       from the context (AddElT
||                           (NYV (Element elType AttrsOk st HFalse))
||                           el
||                           (Valid celType)
||                           elc
||                           (NYV (Element elType AttrsOk st' HTrue))
||                           el2,
||                         AddEl el el2 elc,
||                         Consume st (Elem celType) st',
||                         DetermineElAddEl
||                           (NYV (Element elType AttrsOk st HFalse))
||                           el
||                           (Valid celType)
||                           elc
||                           (NYV (Element elType AttrsOk st' HTrue))
||                           el2)
||       arising from a use of `addEl'
||                    at src/Text/XML/Validated/Types.hs:435:32-40
||     Possible fix:
||       add (AddEl el el2 elc_1) to the context of the instance
declaration
||     In the second argument of `($)', namely `addEl t c'
||     In the expression: PT $ addEl t c
||     In the definition of `addElT':
||         addElT (PT t) (PT c) = PT $ addEl t c


More information about the Haskell mailing list