[Haskell] Ambiguity problem

Mads Lindstrøm mads_lindstroem at yahoo.dk
Fri Jul 22 08:58:49 EDT 2005


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), as fromConstr signatur is:

fromConstr :: forall a. (Data a) => Constr -> a

I do not know where to add it either.

Hope, somebody can enlighten me.


Greetings,

Mads Lindstrøm



More information about the Haskell mailing list