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=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id B57B9BC69 for ; Fri, 19 Oct 2007 02:32:34 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKKXF0fAXQInh2dsb2JhbACOTgIBCAop X-IronPort-AV: E=Sophos;i="4.21,297,1188770400"; d="scan'208";a="4821040" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Oct 2007 02:32:34 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l9J0WXva009570 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 19 Oct 2007 02:32:33 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAHyXF0dC+Vyri2dsb2JhbACOTgIBCAIGExEF X-IronPort-AV: E=Sophos;i="4.21,297,1188770400"; d="scan'208";a="3328481" Received: from ug-out-1314.google.com ([66.249.92.171]) by mail2-smtp-roc.national.inria.fr with ESMTP; 19 Oct 2007 02:32:33 +0200 Received: by ug-out-1314.google.com with SMTP id m3so502861ugc for ; Thu, 18 Oct 2007 17:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:received:date:to:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent:from; bh=kk7Jbfexv5JVQndMEw+gFNYP5rFokV7q8t/MPAxrfM0=; b=EHWjGvMuAZ9LhnVZbkUe1LbvfY+CKve+Ywc9EB/8Qc/ybB2985rQwmFEY+iMF/Y5Kp2gnoJZvU2SXuYxF02+GTZmTabXrXYVYHARNn4lmWNyfNazzmdm0sdHc2d3awzLq64CKWxBW5uuQVCgUCFoCDh8JmNirmURhmXi0PJDH0c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:date:to:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent:from; b=C5leJrxOTAl00NkF7jR+q3yi4j3fUGILaA1P2netEGXO+bBgqMv9bwr7m5BC/WSly5bFaKQsAuAY/3jpFHNd6YCzQ6jwRbqoPXJgrR5BhGrbnCa/FZi6nTw5o2BF/N6kLzBXlDjS0jdLL+2ONjEuV/g60/pYRy7d93eCZqj9IdE= Received: by 10.67.19.11 with SMTP id w11mr2401215ugi.1192753952761; Thu, 18 Oct 2007 17:32:32 -0700 (PDT) Received: from localhost ( [86.206.83.221]) by mx.google.com with ESMTPS id u7sm2371027uge.2007.10.18.17.32.26 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 18 Oct 2007 17:32:28 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Fri, 19 Oct 2007 02:32:58 +0200 Date: Fri, 19 Oct 2007 02:32:58 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] How do apply functors with module constraints? Message-ID: <20071019003258.GA22312@localhost> Mail-Followup-To: Julien Moutinho , caml-list@inria.fr References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-11) From: Julien Moutinho X-Miltered: at concorde with ID 4717FB21.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; functors:01 functor:01 abstraction:01 syntax:01 sig:01 val:01 val:01 functor:01 sig:01 struct:01 iter:01 struct:01 endline:01 ocaml:01 daisy:98 On Thu, Oct 18, 2007 at 07:19:05PM -0400, Alan Falloon wrote: > I am having a really hard time figuring out how to instantiate a functor > when its arguments have module constraints. Here is an example: > [...] > > 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! > > [...] > > Now I'm fresh out of ideas. Here is a new one: % cat fapie.ml module type PIE = sig type pie val bake : unit -> pie val eat : pie -> unit end module type BAKER = functor (Pie: PIE) -> sig val dozen : unit -> Pie.pie array end module type PIG = functor (Pie: PIE) -> sig val feed : Pie.pie -> unit end module Farmer (Pie : PIE) (Baker : BAKER) (Pig : PIG) = struct module Baker = Baker(Pie) module Pig = Pig(Pie) 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 (Pie : PIE) = struct let dozen () = Array.init 13 (fun _ -> Pie.bake ()) end module Daisy (Pie : PIE) = struct let feed p = Pie.eat p; print_endline "OINK!" end module Joe = Farmer(Apple)(Bob)(Daisy) let () = Joe.feed_pigs() % ocaml fapie.ml File "fapie.ml", line 36, characters 12-30: Warning P: this pattern-matching is not exhaustive. Here is an example of a value that is not matched: Pie "" OINK! OINK! OINK! OINK! OINK! OINK! OINK! OINK! OINK! OINK! OINK! OINK! OINK! Hope this helps, Julien.