RE: Avoiding "No explicit method ..." warnings

| This seems to be a lot of mechanism for questionable benefit. A simpler and cleaner | approach, IMHO, is the following: I rather agree. 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? Simon

Simon Peyton-Jones wrote: [snip]
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? [snip] 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.
participants (2)
-
George Russell
-
Simon Peyton-Jones