26 Jul 2000 19:30:42 GMT, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> pisze:

> > instance (ForeignArg fa ha, Call ff hf) => Call (fa -> ff) (ha -> hf) where
> >     callIO f = callIO . convertArg (\fa -> f >>= return . ($fa))
> 
> BTW. I have not tested if it works nor thought how it would execute,
> but I wrote down types of things to use and the resulting type to get,
> and combined them in about the only type-correct way that does not
> use bottoms.
> 
> This is what I love in static typing: there are cases where type
> correctness practically guarantees obtaining what was needed.

       ___    __
  /\   |  )  /  \ |   |  |
 /__\  |-<  (  __ |---|  |
/    \ |  \  \__/ |   |  .

How stupid! I finally did some tests. It does *not* do what was needed.

It executes things in the wrong order. For example when a C function is
applied to a string, it allocates memory, makes a C string, constructs
an IO action that would call the C function, frees the string, and
finally executes the action :-) :-(

How could I present this as an example where "compiles" implies
"it just has to work"?!

The overloaded conversion machinery was so subtle that I of course
have no idea how to do it well. Forget it.

So now C function wrappers written using my foreign library are more
explicit about converting arguments and results. fromIntegral and
ptrToCString string $ \stringPtr -> ...

There are bright sides. It's only Haskell 98 with primitive operations:
multiparameter type classes are no longer there. A few simplifications
were possible by dropping things that were needed only for these
classes (overloaded throwIf* automatically lifted through arguments;
CString as a newtype). The overloaded conversion machinery sometimes
required type annotations to resolve ambiguities.

-- 
 __("<  Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/
  ^^
QRCZAK with a new modem; the old one is deaf


Reply via email to