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 VAA16292; Wed, 28 May 2003 21:55:43 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA16283 for ; Wed, 28 May 2003 21:55:42 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from exch2-villa.corp.zodiacnetworks.com (h179.zodiacnetworks.meer.net [209.157.131.179]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4SJteH18833 for ; Wed, 28 May 2003 21:55:41 +0200 (MET DST) Received: from kontiki.com ([172.16.1.128]) by exch2-villa.corp.zodiacnetworks.com with Microsoft SMTPSVC(5.0.2195.4905); Wed, 28 May 2003 12:55:38 -0700 Message-ID: <3ED5143A.4000706@kontiki.com> Date: Wed, 28 May 2003 12:55:38 -0700 From: Warren Harris User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4a) Gecko/20030401 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] module type constraints problem Content-Type: multipart/alternative; boundary="------------090709030507070401010905" X-OriginalArrivalTime: 28 May 2003 19:55:38.0774 (UTC) FILETIME=[1C88B360:01C32553] X-Spam: no; 0.00; harris:01 abstraction:01 iterated:01 expr:01 val:01 struct:01 mismatch:01 constrain:01 checker:01 equality:01 sig:01 int:01 rec:01 node:02 W7:97 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. --------------090709030507070401010905 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi. I'm wondering if someone on this mailing list can help me with a module type problem. What I would like to achieve is an iteration abstraction (module) that is parameterized by the node and element type of the data to be iterated over. I want to implement this abstraction for different data types including lists, and a language expression type. In the list case, the element type is abstract ('a), and the node type is 'a list. In the expr case, the element type is expr (the exprs themselves, not some sub-element of the exprs), and the node type is also expr. Here's my module type: module type Iter = sig type 'a t val iter : ('a -> unit) -> 'a t -> unit end and here's the list implementation (works great): module ListIter : Iter = struct type 'a t = 'a list let iter f l = List.iter f l end Here's a simlified version of my expr type: type expr = Expr of int * expr * expr | Int of int | Unit But this implementation of the Iter module won't type check: module ExprIter : Iter = struct type 'a t = expr let rec iter f e = f e; match e with Expr(i, a, b) -> iter f a; iter f b | e -> () end Signature mismatch: Modules do not match: sig type 'a t = expr val iter : (expr -> 'a) -> expr -> unit end is not included in Iter Values do not match: val iter : (expr -> 'a) -> expr -> unit is not included in val iter : ('a -> unit) -> 'a t -> unit Adding explicit constraints to the parameters of the iter function don't help either: module ExprIter : Iter = struct type 'a t = expr let rec iter (f:'a -> unit) (e:'a t) = f e; match e with Expr(i, a, b) -> iter f a; iter f b | e -> () end Signature mismatch: Modules do not match: sig type 'a t = expr val iter : (('a t as 'a) -> unit) -> 'a -> unit end is not included in Iter Values do not match: val iter : (('a t as 'a) -> unit) -> 'a -> unit is not included in val iter : ('a -> unit) -> 'a t -> unit Is there some additional way to constrain this problem such that the type checker will accept it? If you look closely, 'a t = 'a = expr yet the type checker is failing to deduce the equality of the two iter function types. Any help would be greatly appreciated, Warren --------------090709030507070401010905 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Hi. I'm wondering if someone on this mailing list can help me with a module type problem. What I would like to achieve is an iteration abstraction (module) that is parameterized by the node and element type of the data to be iterated over. I want to implement this abstraction for different data types including lists, and a language expression type.

In the list case, the element type is abstract ('a), and the node type is 'a list.

In the expr case, the element type is expr (the exprs themselves, not some sub-element of the exprs), and the node type is also expr.

Here's my module type:
module type Iter =
sig
  type 'a t
  val iter : ('a -> unit) -> 'a t -> unit
end
and here's the list implementation (works great):
module ListIter : Iter =
struct
  type 'a t = 'a list
  let iter f l = List.iter f l
end
Here's a simlified version of my expr type:
type expr =
    Expr of int * expr * expr
  | Int of int
  | Unit
But this implementation of the Iter module won't type check:
module ExprIter : Iter =
struct
  type 'a t = expr
  let rec iter f e =
    f e;
    match e with
        Expr(i, a, b) -> iter f a; iter f b
      | e -> ()
end

Signature mismatch:
Modules do not match:
  sig type 'a t = expr val iter : (expr -> 'a) -> expr -> unit end
is not included in
  Iter
Values do not match:
  val iter : (expr -> 'a) -> expr -> unit
is not included in
  val iter : ('a -> unit) -> 'a t -> unit
Adding explicit constraints to the parameters of the iter function don't help either:
module ExprIter : Iter =
struct
  type 'a t = expr
  let rec iter (f:'a -> unit) (e:'a t) =
    f e;
    match e with
        Expr(i, a, b) -> iter f a; iter f b
      | e -> ()
end

Signature mismatch:
Modules do not match:
  sig type 'a t = expr val iter : (('a t as 'a) -> unit) -> 'a -> unit end
is not included in
  Iter
Values do not match:
  val iter : (('a t as 'a) -> unit) -> 'a -> unit
is not included in
  val iter : ('a -> unit) -> 'a t -> unit
Is there some additional way to constrain this problem such that the type checker will accept it? If you look closely, 'a t = 'a = expr yet the type checker is failing to deduce the equality of the two iter function types.

Any help would be greatly appreciated,

Warren
--------------090709030507070401010905-- ------------------- 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