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 SAA15114; Sat, 1 Jun 2002 18:00:35 +0200 (MET DST) 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 SAA14963 for ; Sat, 1 Jun 2002 18:00:34 +0200 (MET DST) Received: from cs.bu.edu (cs.bu.edu [128.197.12.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g51G0X518677 for ; Sat, 1 Jun 2002 18:00:34 +0200 (MET DST) Received: from csa.bu.edu (zhudp@csa [128.197.12.3]) by cs.bu.edu (8.12.2/8.12.2) with ESMTP id g51G0UF2006241; Sat, 1 Jun 2002 12:00:32 -0400 (EDT) Received: from localhost (zhudp@localhost) by csa.bu.edu (8.10.1/8.10.1) with ESMTP id g51G0QU16632; Sat, 1 Jun 2002 12:00:26 -0400 (EDT) X-Authentication-Warning: csa.bu.edu: zhudp owned process doing -bs Date: Sat, 1 Jun 2002 12:00:26 -0400 (EDT) From: dengping zhu X-Sender: zhudp@csa.bu.edu To: Jacques Garrigue cc: caml-list@inria.fr Subject: Re: [Caml-list] about Obj.magic In-Reply-To: <20020601173711W.garrigue@kurims.kyoto-u.ac.jp> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi,Jacques, Thanks for your help! You are right. I solved it by following your suggestion. The problem is exactly what you said: ty is abstarct. After I added the equation ty = ty1 -> ty2 in the signature where ty was defined, I got rid of 'Obj.magic'. Now I am wondering why Ocaml compiler makes the type declaration abstract unless you specify like : type ty = ty1 -> ty2 in the signature, since all the functions are concrete. I took it for granted that the type (ty) must be concrete. I always met some type problems in Ocaml. The common case is as follows: Suppose I define a module 'Test' (test.ml) ---------------------- module Test : TEST = struct type ty = | Int of int | String of string | Float of float end;; ------------------------------ and define the signature as : ----------------------- module type TEST = sig type ty end;; ----------------------- Suppose that type ty is very common among all my modules and I want to reuse it as following: let f x = match x with | Int _ -> 1 | String _ -> 2 | Float _ -> 3 where, I want x to has type ty. In this case, the only method I can find is to open the module 'Test'. Actually, 'open' is not a good way which I tried to avoid. Because I don't know what the expenses of 'open' is. Another reason is if I open a few modules, function overwrite will happen, and it is difficult for me to find out the origins of all the imported functions. Dengping > >The behaviour you describe definitely looks like a bug in the compiler. >But I couldn't reproduce your problem, so I would need the real code >(or a simplified version of it) to check whether this is really a bug. > >Another reason might be difference in behaviour between SML and Caml >modules and functors. In Caml all signatures are opaque. >To check this try writing > >let x = (f (g) : ty1 -> ty2) a > >If you get an error saying that ty is not compatible with ty1 -> ty2, >then this probably means that ty is abstract. This may happen if you >define a signature in which ty appears without the equation ty = ty1 >-> ty2. Adding the equation should solve the problem. > >Hope this helps, but your description is to incomplete to conclude >anything. > >Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners