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 1FBC4BB9A for ; Tue, 15 Nov 2005 14:00:13 +0100 (CET) Received: from osl1smout1.broadpark.no (osl1smout1.broadpark.no [80.202.4.58]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAFD0Cq6031168 for ; Tue, 15 Nov 2005 14:00:12 +0100 Received: from osl1sminn1.broadpark.no ([80.202.4.59]) by osl1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IPZ00M8QYYNJT90@osl1smout1.broadpark.no> for caml-list@yquem.inria.fr; Tue, 15 Nov 2005 14:03:59 +0100 (CET) Received: from h2o.hex.no ([80.203.243.93]) by osl1sminn1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IPZ00EL4YX4E230@osl1sminn1.broadpark.no> for caml-list@yquem.inria.fr; Tue, 15 Nov 2005 14:03:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) (uid 1000) by h2o.hex.no with local; Tue, 15 Nov 2005 14:00:11 +0100 Date: Tue, 15 Nov 2005 14:00:11 +0100 From: =?iso-8859-1?Q?J=F8rgen?= Hermanrud Fjeld Subject: Re: [Caml-list] function specialization In-reply-to: <00a701c5e9da$1b0ebc20$670aa8c0@seva> To: caml-list@yquem.inria.fr Mail-Followup-To: caml-list@yquem.inria.fr Message-id: <20051115130011.GB8700@hex.no> MIME-version: 1.0 Content-type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=_h2o-24292-1132059611-0001-2" Content-disposition: inline References: <00a701c5e9da$1b0ebc20$670aa8c0@seva> User-Agent: Mutt/1.5.9i X-Miltered: at nez-perce with ID 4379DBDC.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 invocation:01 'a-:01 'a-:01 compiler:01 workarounds:01 caml-list:01 beginner's:01 ocaml:01 beginners:01 bug:01 gpg:01 henrik:01 wrote:01 polymorphic:01 X-Attachments: type="application/pgp-signature" name="signature.asc" 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 This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_h2o-24292-1132059611-0001-2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable =46rom the top of my head, with objects (and classes) you can create=20 a method that is polymorphic for each invocation "http://caml.inria.fr/pub/= docs/manual-ocaml/manual005.html#ss:polymorphic-methods". For instance: (**) class type wrapper =3D object method wrap : 'a.('a->unit)->'a->unit end;; let wrapper:wrapper =3D object=20 method wrap : 'a.('a->unit)->'a->unit =3D=20 fun fn arg -> fn arg=20 end ;; let fn1 (v: int) =3D () let fn2 (v: string) =3D () let use =3D wrapper#wrap fn1 1 ; wrapper#wrap fn2 "" ;; let use (wrapper:wrapper) =3D wrapper#wrap fn1 1; wrapper#wrap fn2 "" ;; use wrapper ;; (**) On Tue, Nov 15, 2005 at 02:45:40PM +0300, Vsevolod Fedorov wrote: > Hello! >=20 > I have code like following: > ---- >=20 > type 'a wrap =3D ('a -> unit) -> 'a -> unit >=20 > let wrap fn arg =3D > fn arg >=20 > let fn1 (v: int) =3D () > let fn2 (v: string) =3D () >=20 > let use (wrap: 'a wrap) =3D > wrap fn1 1; > wrap fn2 "" > (* ^^^ This expression has type string -> unit but is here used with > type int -> unit *) >=20 > ------ > and get this error from compiler. > Is there any way to use 'wrap' function for both cases: fn1 and fn2? > Or is there some 'standard' workarounds/solutions for this problem exists? >=20 > Thanks > Seva >=20 >=20 > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >=20 --=20 Sincerely | Homepage: J=F8rgen | http://www.hex.no/jhf | Public GPG key: | http://www.hex.no/jhf/key.txt Truly great madness can not be achieved without significant intelligence. -- Henrik Tikkanen --=_h2o-24292-1132059611-0001-2 Content-Type: application/pgp-signature; name="signature.asc" Content-Transfer-Encoding: 7bit Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDedvb9jvTqPy5VsoRArgdAJ9bYAia3Sng2C9EgIab5JwqOCwNVgCcCnia w/rcpF446TIHQ7Vaaz7C9ac= =3Dru -----END PGP SIGNATURE----- --=_h2o-24292-1132059611-0001-2--