From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 4A4B2BB9C for ; Thu, 15 Sep 2005 12:34:19 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j8FAYGEq004006 for ; Thu, 15 Sep 2005 12:34:16 +0200 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 MAA17357 for ; Thu, 15 Sep 2005 12:34:15 +0200 (MET DST) Received: from efil.de (efil.de [81.3.25.37]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j8FAYFag004003 for ; Thu, 15 Sep 2005 12:34:15 +0200 Received: by efil.de (Postfix, from userid 1000) id 4345D99BCAB; Thu, 15 Sep 2005 12:34:41 +0200 (CEST) Date: Thu, 15 Sep 2005 12:31:48 +0200 From: Ingo Bormuth To: Jacques Garrigue , =?iso-8859-1?Q?St=E9phane?= Glondu Cc: caml-list@inria.fr Subject: [SOLVED] Reference to polymorphic function ? Message-ID: <20050915103148.GA21415@kruemel> Reply-To: Ingo Bormuth References: <20050913123843.GA9640@kruemel> <20050915.084814.127622622.garrigue@math.nagoya-u.ac.jp> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OXfL5xGRrasGEqWY" Content-Disposition: inline In-Reply-To: <20050915.084814.127622622.garrigue@math.nagoya-u.ac.jp> X-Attribution: Ingo Bormuth X-Url: http://ibormuth.efil.de/contact User-Agent: Mutt/1.5.8i Cc: ingo@bormuth.org X-j-chkmail-Score: MSGID : 43294E28.000 on nez-perce : j-chkmail score : X : 0/20 1 X-j-chkmail-Score: MSGID : 43294E27.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 43294E28.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43294E27.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; serialize:01 serialize:01 ingo:98 efil:98 48,:98 ingo:98 efil:98 wrote:01 wrote:01 polymorphic:01 marshal:01 marshal:01 define:01 algorithm:01 int:01 X-Attachments: type="application/pgp-signature" X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2005-09-15 08:48, Jacques Garrigue wrote: > > The simplest way to do this is to define a new type: >=20 > type put =3D {put: 'a -> unit} ;; > let put =3D {put =3D put_to_screen} ;; > put.put "test";; > put.put 5;; >=20 Thank you !!! That's exactly what I was looking for. On 2005-09-14 23:08, St=E9phane Glondu wrote: > > However, I didn't catch what=20 > you want to do with thoses references: maybe there is another way to=20 > achieve what you want? >=20 Just for the notes:=20 I wrote a serilisation function to pack a quite complex data structure=20 into one string. That string is then used to feed a file, socket,=20 sha1 or encryption algorithm.=20 I want to reduce overhead and directly marshal the values to the=20 destination without generating the intermediate string whenever possible. This is a simple profe of principal prototype : type data =3D | Int of int | Float of float | Str of string ;; type target =3D=20 | Screen | Channel of out_channel ;; type put =3D { str: string -> unit ; raw: 'a. 'a -> unit } ;; let serialize data target =3D let put =3D ref { str =3D ( fun s -> () ); raw =3D ( fun v -> () ) } in let write_value key value =3D !put.str ( "<" ^ key ^ ">" ) ; !put.raw value ; !put.str ( "" ) in let write_data () =3D match data with | Int i -> write_value "int" i | Float f -> write_value "float" f | Str s -> write_value "str" s in let init_target =3D match target with | Screen -> put :=3D {=20 str =3D print_string ; raw =3D let f v =3D print_string ( Marshal.to_string v [] ) in = f } | Channel chan -> put :=3D {=20 str =3D output_string chan ; raw =3D let f v =3D ( Marshal.to_channel chan v [] ) in f } in init_target ; write_data () ;; serialize ( Int 123 ) Screen=20 ;; serialize ( Float 3.14 ) Screen=20 ;; serialize ( Str "Hello" ) ( Channel ( open_out "/tmp/seri" ) )=20 ;; --=20 +--------------------------------------------------------+ | Ingo Bormuth, voicebox & telefax: +49-12125-10226517 | | GnuPG key 86326EC9 at http://ibormuth.efil.de/contact | +--------------------------------------------------------+ --OXfL5xGRrasGEqWY Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDKU2UNzWqdIYybskRAjXXAJ9a7x6WWaXa2NV6ZSjuG+niqj54pgCdHtGc 7XAW4+joAGEuiuQwK0EI1Sg= =dSXN -----END PGP SIGNATURE----- --OXfL5xGRrasGEqWY--