22 Jul
2005
22 Jul
'05
3:33 p.m.
Am Freitag, 22. Juli 2005 15:56 schrieb Mads Lindstrøm:
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.
But somehow you have to tell the compiler what type you want your argument be converted into. If this is always the same type, you can implement foo like this: foo arg = numChildren (fromConstr arg :: YourType)
[...]
Best wishes, Wolfgang