Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] dynamically loading C functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: qrczak@k...
Subject: Re: [Caml-list] dynamically loading C functions
Mon, 05 Mar 2001 12:28:26 -0800, Chris Hecker <checker@d6.com> pisze:

> - I can tell people to "cast" the 'a return type, so you'd do this:
> 
> let f = (get_function "TheFunction: float -> float -> int" : float -> float -> int)
> 
> but, this requires the error prone double-specification of the type,

You can provide combinators to build the type information:

val int_t   : int t
val float_t : float t
val (@->)   : 'a t -> 'b t -> ('a -> 'b) t
(* Begins with @ so it's right-associative :-) *)

val get_function : string -> 'a t -> 'a

let f = get_function "TheFunction" (float_t @-> float_t @-> int_t)

(I just imagined the idea in Haskell and translated implicit Haskell's type
classes into explicit OCaml's dictionary passing.)

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr