[Haskell] Ambiguous type variable when using Data.Generic
Taral
taralx at gmail.com
Sat May 20 15:58:28 EDT 2006
On 5/20/06, Bas van Dijk <basvandijk at home.nl> wrote:
> How can I make this work?
As far as I know, you can't. To see the problem, rewrite it using dictionaries:
data Simplify a = Simplify { simplify :: a -> a }
simplify_HsExp (HsInfixApp e1 op e2) = HsApp (HsApp (opToExp op) e1) e2
simplify_HsExp (HsLeftSection e op)= HsApp (opToExp op) e
simplify_HsExp (HsRightSection op e) = HsApp (opToExp op) e
simplify_HsExp (HsParen e) = e
simplify_HsExp e = e
Simplify_HsExp = Simplify simplify_HsExp
etc.
You will end up with a bunch of Simplify_* objects. Now in the application:
preProcess = everywhere (mkT simplify)
how do you convert this? If you use (mkT (simplify ...)), you're
fixing simplify to only one type. If you use (mkT simplify), you get a
type error.
GHC is telling you that you need to tell it which instance of simplify
to use. In your example, you can use:
everywhere (mkT (simplify :: HsExp -> HsExp))
. everywhere (mkT (simplify :: HsPat -> HsPat))
. everywhere (mkT (simplify :: HsRhs -> HsRhs))
Of course, that's not any simpler.
--
Taral <taralx at gmail.com>
"You can't prove anything."
-- Gödel's Incompetence Theorem
More information about the Haskell
mailing list