Type checking question

Adrian Hey ahey@iee.org
Fri, 2 Nov 2001 16:23:34 +0000


I've been playing around with GTK+HS recently.
This makes extensive use of Haskell classes, so I 
sometimes get strange type errors like this one..

textNew (creates a new text widget) has type:
textNew :: AdjustmentClass adj => Maybe adj -> Maybe adj -> IO Text 

But when I try to create one using:
	txt <- textNew Nothing Nothing

GHC complains:
    Ambiguous type variable(s) `a'
        in the constraint `GtkAdjustment.AdjustmentClass a'
    arising from use of `textNew' at Main.hs:82
    in a `do' expression pattern binding:
        txt <- textNew Nothing Nothing

My first thought was that I need a type signature for txt,
but seeing as txt has to be type IO Text, I dont think
that's possible (because 'adj' is not referenced).
Is that correct?

So, what should one do in this situation?
Something like this perhaps..
 myNothing :: Maybe dummyAdjustmentClassInstance
 myNothing = Nothing
 txt <- textNew myNothing myNothing
I'm pretty sure that would do it, but it seems like
an ugly solution. Is there a better way?

Adrian Hey