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 RAA19026; Sat, 23 Feb 2002 17:09:58 +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 RAA18868 for ; Sat, 23 Feb 2002 17:09:56 +0100 (MET) Received: from mbg.sphere.ne.jp (mbg.sphere.ne.jp [203.138.71.44]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g1NG9sv15762 for ; Sat, 23 Feb 2002 17:09:55 +0100 (MET) Received: from localhost (pl039.nas521.k-tokyo.nttpc.ne.jp [210.165.66.39]) by mbg.sphere.ne.jp (8.9.3+3.2W/3.7W) with ESMTP id BAA18076 for ; Sun, 24 Feb 2002 01:09:42 +0900 (JST) To: caml-list@inria.fr Subject: [Caml-list] subtyping questions X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.1 (AOI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020224011022E.yoriyuki@ms.u-tokyo.ac.jp> Date: Sun, 24 Feb 2002 01:10:22 +0900 From: YAMAGATA yoriyuki X-Dispatcher: imput version 991025(IM133) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Recently I was toying with Unicode data types but now get stuck. It's not a "serious" project and if I fail, no one would be harmed. So just if you give me a suggestion using your spare time, I would appreciate greatly. An appropriate Unicode string representation differs depending on application. For example, sometimes arrays of OS-dependent "wch" are required, while sometimes OS-independent realization is proffered. So I define the basic virtual class for Unicode string (called "Ustorage.t") and want to make functions work on all subclass of "Ustorage.t". However, I soon stuck when making equivalent of Buffer in stdlib. What I want to do is, making a buffer return its contents as any given subclass of "Ustorage.t". First idea is passing a "constructor", which receives any instant of subclass of "Ustorage.t" and returns its copy in a desired type, as an argument and applying a buffer internal to the constructor. I'd like generalise the type of the function getting contents from a buffer as "(#Ustorage.t -> #Ustorage.t as 'a) -> t -> 'a" (t is the type of buffers). However, type checker gives the type "t_internal -> #Ustorage.t as 'a -> t -> 'a" and doesn't allow such generalisation via module interface. (t_internal is the type of internal buffer, which I don't want to publish.) OK, next I tried to coerce an internal buffer to an instant of "Ustorage.t" and want to get the type "Ustorage.t -> #Ustorage.t as 'a -> t -> 'a". However, coercion doesn't work, perhaps due to binary methods. So, what I should do? Or, what I try to do is too weird to realize? Here are class interfaces of related objects. (precisely speaking, Ustorage.t is parametrised by its "cursor" type. So the type expression "Ustorage.t" and "#Ustorage.t" appeared above, are abbreviation of "Usotrage.cur Ustorage.t" and "#Ustorage.cur #Ustorage.t".) In the file ustorage.mli, class virtual cur : object ('a) (* Uchar.t is the type of unicode characters *) method virtual get : Uchar.t method virtual copy : unit -> 'a method virtual next : 'a method virtual prev : 'a method virtual incr : unit -> unit method virtual decr : unit -> unit method virtual eq : 'a -> bool method virtual leq : 'a -> bool (*<=*) method virtual geq : 'a -> bool (*>=*) method virtual dst : 'a -> int (*distance*) end class virtual ['b] t : object ('a) constraint 'b = #cur method virtual first : 'b method virtual last : 'b method virtual len : int end in ubuffer.ml class t_internal : int -> int -> int -> string -> object ('a) inherit [cur_internal] Ustorage.t val rep_len : int (* number of UCS-characters *) val rep_point : int (* position of the newly added character.*) val rep_buf : string ref method len : int method point : int method buf : string method clear : unit -> unit method reset : unit -> unit method add_char : Uchar.t -> unit method add_buffer : 'a -> unit method copy : unit -> 'a method append : 'a -> 'a method first : cur_internal method last ; cur_internal method resize : int -> unit method private put_byte : char -> unit method private add_code : int -> unit end and cur_internal : string ref -> int ref -> int ref -> object('a) inherit Ustorage.cur val mutable p : int method get : Uchar.t method copy : unit -> 'a method incr : unit -> unit method decr : unit -> unit method next : 'a method prev :'a method eq :'a -> bool method leq : 'a -> bool method geq : 'a -> bool method dst : 'a -> int method pos : int method storage : stirng ref method last_pos : int ref end Sorry for a lengthy mail. ------------------- 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