From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DD89BBCAF for ; Sun, 3 Jul 2005 14:37:03 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j63Cb1V7019745 for ; Sun, 3 Jul 2005 14:37:03 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j63Caw4s003883 for ; Sun, 3 Jul 2005 21:36:58 +0900 (JST) Date: Sun, 03 Jul 2005 21:37:37 +0900 (JST) Message-Id: <20050703.213737.63742895.garrigue@math.nagoya-u.ac.jp> To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] bizarre type From: Jacques Garrigue In-Reply-To: References: <000d01c57dab$21871e30$14b2a8c0@wiko> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 42C7DBED.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 damien:01 damien:01 val:01 foo:01 bool:01 abbreviation:01 val:01 foo:01 subtyping:01 bool:01 overriding:01 abstract:01 doligez:01 doligez:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: From: Damien Doligez > If I understand correctly, this is your problem: > > Objective Caml version 3.08.3+4 (2005-06-21) > > # type 'a marshalled=string;; > type 'a marshalled = string > # let make (x : 'a)=(Marshal.to_string x [] : 'a marshalled);; > val make : 'a -> 'a marshalled = > # make 1 = make "foo";; (* int marshalled is the same as string > marshalled *) > - : bool = false > > It works better you use a concrete type instead of an abbreviation: > > # type 'a marsh2 = Marsh of string;; > type 'a marsh2 = Marsh of string > # let make2 (x : 'a) = (Marsh (Marshal.to_string x []) : 'a marsh2);; > val make2 : 'a -> 'a marsh2 = > # make2 1 = make2 "foo";; (* int marsh2 is not the same as string > marsh2 *) > ^^^^^^^^^^^ > This expression has type string marsh2 but is here used with type int > marsh2 Actually this is not a very good suggestion from the point of view of safety, as this useless parameter can still be modified by subtyping: # make2 1 = (make2 "foo" :> _ marsh2);; - : bool = false If you care about safety, you must either use an abstract type, or a private type in ocaml-3.09 (not 3.08!). On the other, if you want to keep the possibility of overriding the parameter, while detecting non-annotated cases, this may actually be a good approach. Jacques Garrigue