Avoiding "No explicit method ..." warnings
Tue, 21 Jan 2003 16:43:05 +0100
Simon Peyton-Jones wrote:
> One other idea though. Suppose you say
> class ComplicatedClass x where
> _simpleTitleFn :: x -> String
> muchMoreComplicatedTitleFn :: extra arguments -> x -> IO ...
> In general GHC doesn't report "warning unused" for variables whose name
> begin with an underscore. In the case of class methods, I don't think
> it suppresses the warning, but that would be an easy change to make.
> Indeed, it would arguably be more consistent to do so anyway
> > #-}) which compiles exactly as normal except that (1) no warning is
> > given for instances which don't define it; (2) a warning is given
> > whenever anyone outside the class declaration *uses* simpleTitleFn.
> The "_" idea would achieve (1). You could get (2) by not exporting the
> "_" method from the module defining ComplicatedClasss.
> How would that be?
Yes, this looks just as good as my original idea, if not better. Especially
as it "would be an easy change to make".
In fact there are some cases where I might want to use "simpleTitleFn" on a
"Trust me, it's defined for this type" basis, but that could be achieved by
exporting an equivalent, but deprecated, function.