freeHaskellFunctionPtr

Manuel M. T. Chakravarty chak at cse.unsw.edu.au
Wed Jan 3 19:59:41 EST 2001


qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) wrote,

> Wed, 3 Jan 2001 21:12:54 +1100, Fergus Henderson <fjh at cs.mu.oz.au> pisze:
> 
> > > Yes: me, for the readline library.
> > 
> > Could you be more specific?
> 
> typedef struct {...} KEYMAP_ENTRY;
> typedef KEYMAP_ENTRY *Keymap;
> typedef int Function();
> 
> 
> int rl_generic_bind (int type, char *keyseq, char *data, Keymap map)
> 
> If type == ISFUNC:
>     data should be a value of type Function *, cast to char *.
>     It will be applied to two int values.
> If type == ISMACR:
>     data should be a string.
> If type == ISKMAP:
>     data should be a value of type Keymap, cast to char *.
> 
> 
> Function *rl_function_of_keyseq (char *keyseq, Keymap map, int *type)
> 
> Returns data as set by rl_generic_bind, cast to Function * this time,
> and sets type appropriately.

I was actually thinking about situations like this and
wondering whether it wouldn't be cleaner to have a Haskell
binding as follows:

foreign import rl_generic_bind_func 
  :: CInt -> Ptr CChar -> FunPtr (Int -> Int -> IO ())) -> Ptr KeyMap -> IO Int

bindFunc :: String -> (Int -> Int -> IO ()) -> KeyMap -> IO
bindFunc ... = do
	         ...
		 rl_generic_bind_func ISFUNC ...
		 ...

foreign import rl_generic_bind_macr
  :: CInt -> Ptr CChar -> Ptr CChar -> Ptr KeyMap -> IO Int

<and so on>

But I think, you are right: Why try to be cleaner than the
underlying C library?  It would probably not gain anything
and may make our life harder.

Fergus Henderson <fjh at cs.mu.oz.au> wrote,

> Your examples of dlsym() and readline are sufficiently convincing
> that I agree that these conversion functions should be left in.
> But they should be documented properly.
> (The fact that Perl and other software has undocumented
> non-portabilities doesn't imply that we should be lax in
> documenting our own stuff!)

I agree with this, too.

Cheers,
Manuel




More information about the FFI mailing list