From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id DAC6ABC69 for ; Fri, 19 Oct 2007 01:20:14 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAABqGF0fAXQInh2dsb2JhbACOTQIBCAop X-IronPort-AV: E=Sophos;i="4.21,297,1188770400"; d="scan'208";a="18301080" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 19 Oct 2007 01:20:14 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l9INK9lu008093 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 19 Oct 2007 01:20:14 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAP+GF0dQW+UCh2dsb2JhbACOTQIBCAop X-IronPort-AV: E=Sophos;i="4.21,297,1188770400"; d="scan'208";a="3293663" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail1-smtp-roc.national.inria.fr with ESMTP; 19 Oct 2007 01:20:09 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Iieen-00005a-4X for caml-list@inria.fr; Thu, 18 Oct 2007 23:20:01 +0000 Received: from dsl-207-112-67-87.tor.primus.ca ([207.112.67.87]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 18 Oct 2007 23:20:01 +0000 Received: from alan.falloon by dsl-207-112-67-87.tor.primus.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 18 Oct 2007 23:20:01 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Alan Falloon Subject: How do apply functors with module constraints? Date: Thu, 18 Oct 2007 19:19:05 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dsl-207-112-67-87.tor.primus.ca User-Agent: Thunderbird 1.5.0.13 (X11/20070824) Sender: news X-Miltered: at concorde with ID 4717EA29.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; functors:01 functor:01 sig:01 val:01 val:01 sig:01 struct:01 iter:01 struct:01 endline:01 abstraction:01 syntax:01 syntax:01 farmer:98 daisy:98 I am having a really hard time figuring out how to instantiate a functor when its arguments have module constraints. Here is an example: module type PIE = sig type pie val bake : unit -> pie val eat : pie -> unit end module type BAKER = sig module Pie : PIE val dozen : unit -> Pie.pie array end module type PIG = sig module Pie : PIE val feed : Pie.pie -> unit end (* Need a module constraint to make sure that the baker and pig are talking about the same pie *) module Farmer (Baker : BAKER) (Pig : PIG with module Pie = Baker.Pie) = struct let feed_pigs () = let pies = Baker.dozen () in Array.iter Pig.feed pies end module Apple : PIE = struct type pie = Pie of string let bake () = Pie "apple" let eat (Pie "apple") = () end module Bob : BAKER = struct module Pie = Apple let dozen () = Array.init 13 (fun _ -> Pie.bake ()) end module Daisy : PIG = struct module Pie = Apple let feed p = Pie.eat p; print_endline "OINK!" end module Joe = Farmer(Bob)(Daisy) (*BOOM*) let () = Joe.feed_pigs() However, this fails to compile because when I try to make module Joe because Bob.Pie and Daisy.Pie aren't the same. Fair enough, thats what abstraction is for, however I can't figure out the syntax to instantiate Joe! I tried this: module Joe = Farmer(Bob)(Daisy:PIG with module Pie=Bob.Pie) But then I get a syntax error (?) File "bar.ml", line 39, characters 30-31: Syntax error: ')' expected File "bar.ml", line 39, characters 24-25: This '(' might be unmatched Now I'm fresh out of ideas. Thanks Alan Falloon