From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA27253; Tue, 6 Mar 2001 01:16:48 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA27363 for ; Tue, 6 Mar 2001 01:16:47 +0100 (MET) Received: from mta6.snfc21.pbi.net (mta6.snfc21.pbi.net [206.13.28.240]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f260Gk929924 for ; Tue, 6 Mar 2001 01:16:46 +0100 (MET) Received: from checkerlap.d6.com ([64.160.53.238]) by mta6.snfc21.pbi.net (Sun Internet Mail Server sims.3.5.2000.01.05.12.18.p9) with ESMTP id <0G9R00H0C1SVDZ@mta6.snfc21.pbi.net> for caml-list@inria.fr; Mon, 5 Mar 2001 16:10:08 -0800 (PST) Date: Mon, 05 Mar 2001 16:10:56 -0800 From: Chris Hecker Subject: Re: [Caml-list] dynamically loading C functions In-reply-to: X-Sender: def6@shell16.ba.best.com To: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk), caml-list@inria.fr Message-id: <4.3.2.7.2.20010305155358.00e26850@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset="us-ascii" References: <4.3.2.7.2.20010304235205.00dea6a0@shell16.ba.best.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >You can provide combinators to build the type information: Wow, that's pretty cool. I'm not that familiar with abstract types and modules in caml (or any functional language), so this was kind of an eye opener. I think I understand how they work a bit more now, thanks. I do have one thing I can't figure out. Here's my test module: module C: sig type 'a t val int_t : int t val float_t : float t (* Begins with @ so it's right-associative :-) *) val (@->) : 'a t -> 'b t -> ('a -> 'b) t val get_function : string -> 'a t -> 'a val conv : 'a t -> int list end = struct type 'a t = T of int | Tl of int list let int_t = T 1 let float_t = T 2 let (@->) a b = match a,b with (T a,T b) -> Tl [a;b] | (T a,Tl b) -> Tl (a :: b) | (Tl a,Tl b) -> Tl (a @ b) | (Tl a,T b) -> Tl (a @ [b]) let get_function s l = Obj.magic s (* just get it to compile *) let conv (Tl a) = a end The way I've done 'a t is as a variant int list. This works, but my @-> flattens nested lists because of the pattern match, so while the type system differentiates between # (float_t @-> int_t @-> float_t @-> float_t @-> int_t);; - : (float -> int -> float -> float -> int) C.t = and (note the nested parens): # (float_t @-> (int_t @-> float_t @-> float_t) @-> int_t);; - : (float -> (int -> float -> float) -> int) C.t = my internal representation doesn't: # conv (float_t @-> int_t @-> float_t @-> float_t @-> int_t);; - : int list = [2; 1; 2; 2; 1] # conv (float_t @-> (int_t @-> float_t @-> float_t) @-> int_t);; - : int list = [2; 1; 2; 2; 1] I thought I could fix this by saying type 'a t = T of int | Tl of 'a t list, but that seems to constrain (@->) to be 'a t -> 'a t -> 'a t and I lose the cruicial ('a -> 'b) t combinator (not sure if I'm using that word correctly) and I get a type error. Any idea how I could get it to nest? Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr