I've made overloaded curried printf for fun
<http://qrczak.ids.net.pl/Printf.hs> and faced a problem.
------------------------------------------------------------------------
class FormatIO a where
ioprintf :: (String -> IO ()) -> String -> a
combineIO :: IO () -> a -> a
instance (Formattable a, FormatIO b) => FormatIO (a -> b) where ...
instance FormatIO (IO ()) where ... -- This instance requires -fglasgow-exts
------------------------------------------------------------------------
ioprintf has types
(String->IO()) -> String -> a -> b -> ... -> z -> IO ()
for any number of types a,b,...,z from the Formattable class.
The problem is that when the typechecker knows that the result of some
application of ioprintf must have the type "IO a" for some type a
(because it is used in the middle of a "do" sequence), it does not
deduce that it's exactly "IO ()".
I understand that it follows from type inference rules and that I
could add e.g. FormatIO (IO Int) instance. But I don't know if it
is possible to specify that I don't want to be allowed to provide
any other "FormatIO (IO something)" instance, and that I want the
typechecker to automatically deduce "IO ()" whenever it must be
"IO something". Functional dependencies maybe?
If it's not possible with the current rules, maybe some next extension
of the type system? :-)
I could let it return polymorphic "IO a" (returning bottom) and avoid
this problem. But although nobody would probably ever want to evaluate
the unit returned by printf, it would look unnatural.
Similar problem is with my Haskell<->OCaml interface.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/ GCS/M d- s+:-- a22 C+++$ UL++>++++$ P+++ L++>++++$ E-
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-