[Haskell] Ambiguity problem

Wolfgang Jeltsch wolfgang at jeltsch.net
Fri Jul 22 11:33:06 EDT 2005


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


More information about the Haskell mailing list