Why does implementation A work fine, but implementation B gives me “types do not unify”?
-- a function which operates on records with a field 'common' sd :: forall a. { common :: Common | a} -> { common :: Common | a} sd r = set _dispSelf Nothing r -- this takes a function for altering records with 'Common' and an Obj. clearObjDisplay :: forall a. ({ common :: Common | a} -> { common :: Common | a }) -> Obj -> Obj -- Obj has several constructors. -- Every one has a record type as data which -- includes a field of type Common, so they should all match -- 'forall a. { common :: Common }'. The exact record type is different -- for each object, however. -- implementation A. Calling the function 'sd' defined -- above to alter the record. clearObjDisplay g (ObjText r) = ObjText $ sd r clearObjDisplay g (ObjImg r) = ObjImg $ sd r -- implementation B. Using the function passed as argument 'g' clearObjDisplay g (ObjText r) = ObjText $ g r clearObjDisplay g (ObjImg r) = ObjImg $ g r
Mike