Hi Wolfgang Thank you very much for the reply. I added an extra parameter to the function, so the code now looks like:
foo :: (Data a) => a -> Constr -> Int foo idType = (numChildren idType) . fromConstr numChildren :: (Data a) => a -> a -> Int numChildren _ x = sum $ gmapQ (\_ -> 1) x and it works. However, it does seem ugly to have an extra argument, just to please the type checker. This extra argument can fortunately be limited to a few functions, in the program I am working on. /Mads Lindstrøm Wolfgang Jeltsch: > Am Freitag, 22. Juli 2005 14:58 schrieb Mads Lindstrøm: > > Hi > > > > I am struggling with an ambiguity problem. I have the following code: > > > foo :: Constr -> Int > > > foo = numChildren . fromConstr > > > > > > numChildren :: (Data a) => a -> Int > > > numChildren x = sum $ gmapQ (\_ -> 1) x > > > > which I thought would work, but the GHC-6.4 says: > > > Ambiguous type variable `a' in the constraint: > > > `Data a' arising from use of `numChildren' at AutoForm.hs:87:6-16 > > > Probable fix: add a type signature that fixes these type variable(s) > > > > I cannot see why I need to add (Data a), > > (Data a) is a context, not a type signature. > > I think, the problem is that fromConstr converts to a value of an unknown > type > which is converted by numChildren afterwards. The compiler cannot know which > type it has to use for the intermediate value, i.e., which concrete > implementation of numChildren and fromConstr it has to use. > > > [...] > > Best wishes, > Wolfgang > _______________________________________________ > Haskell mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell > _______________________________________________ Haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell
