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 CAA27692; Tue, 6 Mar 2001 02:00:48 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA28043 for ; Tue, 6 Mar 2001 02:00:47 +0100 (MET) Received: from mta6.snfc21.pbi.net (mta6.snfc21.pbi.net [206.13.28.240]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f2610k904544 for ; Tue, 6 Mar 2001 02:00: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 <0G9R00K2A3V69M@mta6.snfc21.pbi.net> for caml-list@inria.fr; Mon, 5 Mar 2001 16:54:42 -0800 (PST) Date: Mon, 05 Mar 2001 16:55:25 -0800 From: Chris Hecker Subject: Re: [Caml-list] dynamically loading C functions In-reply-to: <4.3.2.7.2.20010305155358.00e26850@shell16.ba.best.com> 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.20010305164831.00e2cd60@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 >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? Okay, I fixed this by introducing another type that didn't need to be parameterized (see below). I guess I should have thought of that earlier. Now my only problem is that I collapse int_t -> (int_t -> int_t) to int_t -> int_t -> int_t, which is correct for languages with currying, but C doesn't curry, so I need to keep those parens around to generate the right type. Not sure how to do this, but I might be able to pull something fancy...gotta think about it. Or, maybe I should left associate, which will make the return type last always, rather than first, and any time I come across a list on the right I should preserve it... Chris (* handles nested function types *) 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 print : 'a t -> unit end = struct type tt = T of int | Tl of tt list type 'a t = tt let int_t = T 1 let float_t = T 2 let (@->) a b = match a,b with ((T _ as a),(T _ as b)) -> Tl [a;b] | ((T _ as a),Tl b) -> Tl (a :: b) | (((Tl _) as a),((Tl _) as b)) -> Tl [a;b] | (((Tl _) as a),(T _ as b)) -> Tl [a;b] let get_function s l = Obj.magic s (* just get it to compile *) let print el = let rec doprn el = match el with T a -> Printf.printf " %d " a | Tl a -> begin print_string " [ "; List.iter ~f:doprn a; print_string " ] " end in doprn el end ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr