25 Jul 2000 08:56:09 GMT, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> pisze:
> Ah, I was once doing such overloading of IO functions. I tried but
> was not able to adapt it to "threaded" foreign calls.
Help! Now it looks easier, but still I can't get it.
Assume we have:
class Arg f h where
arg :: (f -> IO a) -> h -> IO a
I want to unify the following functions:
call0:: IO a -> IO a
call0 = id
call1:: Arg f1 h1 => (f1 -> IO a) -> h1 -> IO a
call1 = arg
call2:: (Arg f1 h1, Arg f2 h2)
=> (f1 -> f2 -> IO a) -> h1 -> h2 -> IO a
call2 f h1 h2 = arg (\f1 -> call1 (f f1) h2) h1
call3:: (Arg f1 h1, Arg f2 h2, Arg f3 h3)
=> (f1 -> f2 -> f3 -> IO a) -> h1 -> h2 -> h3 -> IO a
call3 f h1 h2 h3 = arg (\f1 -> call2 (f f1) h2 h3) h1
call4:: (Arg f1 h1, Arg f2 h2, Arg f3 h3, Arg f4 h4)
=> (f1 -> f2 -> f3 -> f4 -> IO a) -> h1 -> h2 -> h3 -> h4 -> IO a
call4 f h1 h2 h3 h4 = arg (\f1 -> call3 (f f1) h2 h3 h4) h1
...
Conversion of the return value will be later, now only these.
I want to produce something like
call :: Call f h => f -> h
instance Call (IO a) (IO a)
instance (Arg fa ha, Call ff hf) => Call (fa -> ff) (ha -> hf)
I don't have an idea which functions to put in a class to tie the
recursion! The problem is that arg needs IO just here, and in a
class IO is hidden deep inside the function type.
Maybe some additional type parameters with functional
dependencies could help here. I've already done a similar case,
<http://qrczak.ids.net.pl/Printf.hs>, but that was easier.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/ GCS/M d- s+:-- a23 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-