Hi,

I'm trying to do something like the following:

class Foo a where
    doit :: (String -> IO ()) -> a -> IO ()
 
instance Foo Int where
    doit f = f . show

instance Foo Char where
    doit f = f . (:[])

So now I have a "doit" function for Ints and Chars, that takes a function and does the IO with the given function. Now I could define function p as

p :: (Foo a) => a -> IO ()
p = doit putStrLn

so I could do

main = do
    p 3
    p 'X'

in main, but I would like to compeltely hide the fact from p that it somehow belongs to the Foo class, so I would like to do something like this:

class Foo a => Bar a where
    p2 :: a -> IO ()
    p2 = doit putStrln

but, though Foo Int and Foo Char are defined, Bar Int and Bar Char are not defined automatically, so given this class definition I will not be able to call
p2 3
and
p2 'X'

Is there still some way to do something like this?

Thanks,
Istvan