From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p380iuwr017292 for ; Fri, 8 Apr 2011 02:44:56 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlsBAJlZnk3UTWUIkGdsb2JhbACES6FGFAEBAQEJCQ0HFAQhiHmnEYJfAY45BYEpg0x4kSw X-IronPort-AV: E=Sophos;i="4.63,320,1299452400"; d="scan'208";a="80423133" Received: from mx4.wp.pl ([212.77.101.8]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 08 Apr 2011 02:44:50 +0200 Received: (wp-smtpd smtp.wp.pl 12874 invoked from network); 8 Apr 2011 02:44:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1302223489; bh=XR1xoS1IewGmmrlFdvlCFWlOVE4Rw/mdaPIN3dr4LWY=; h=From:To:Subject; b=JRhyim52H3T6jVpKzGtmW8MpME1cBodzXW2rSO2iFMYVZe9+6bpmxt2cwZbdI4h4V Hzxhoo4qKxgzexqmAD/y6I0m8xQJjbF7hN7bvDAvp0KT+tgHbiDHAq9dsFZGa9QdMf vVTM0E/evxxFP34zXvxZTVJowXvyMJbHzJXWnACc= Received: from 18-161.2-0.pl (HELO [192.168.1.101]) (d0@[91.189.18.161]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with AES256-SHA encrypted SMTP for ; 8 Apr 2011 02:44:49 +0200 Message-ID: <4D9E5A80.3010902@wp.pl> Date: Fri, 08 Apr 2011 02:44:48 +0200 From: Dawid Toton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: caml-list References: <4D9E28D2.1050808@wp.pl> <1302212990.8429.1150.camel@thinkpad> In-Reply-To: <1302212990.8429.1150.camel@thinkpad> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [geNU] Subject: [Caml-list] Re: What is an applicative functor? Thanks for the very quick answer. Does it mean that I can render a module to be not applicative by adding a record type to it? This would break some existing code which relies on equality of some other types? On 2011-04-07 23:49, Gerd Stolpmann wrote: > Am Donnerstag, den 07.04.2011, 23:12 +0200 schrieb Dawid Toton: >> What does it mean that a functor is applicative? > Roughly: If you apply a functor twice with the same input modules, the > opaque types in the output remain compatible. For instance: > > module S1 = Set.Make(String) > module S2 = Set.Make(String) > > Now, S1.t and S2.t are type-compatible, although this type is opaque. > (E.g. you can do S1.empty = S2.empty.) But sometimes it doesn't work this way: module Make2(X : sig end) = struct type s end module M1 = Make2(struct end) module M2 = Make2(struct end) let g (a : M1.s) (b : M2.s) = a = b;; Error: This expression has type M2.s but an expression was expected of type M1.s > Compare this with: > > module Make(X : sig end) = struct type t = Variant end > module M1 = Make(struct end) > module M2 = Make(struct end) > > Now, M1.t and M2.t are incompatible - for nominal types like variants > the functors aren't applicative, and each instance is a thing of its > own: > > # M1.Variant = M2.Variant;; > Error: This expression has type M2.t but an expression was expected of > type M1.t > Honestly, I don't get it: module Make(X : sig end) = struct type t = Variant end module Empty = struct end module M1 = Make(Empty) module M2 = Make(Empty) ;; M1.Variant = M2.Variant ;; Toplevel responds with: module Make : functor (X : sig end) -> sig type t = Variant end module Empty : sig end module M1 : sig type t = Make(Empty).t = Variant end module M2 : sig type t = Make(Empty).t = Variant end # - : bool = true So I get applicative functor with a nominal type? >> Is there any analogy between applicative functors in OCaml and the >> Applicative type class of Haskell? I have some idea of it: we consider two types that play nicely together. I pass them through a functor. If the functor is applicative, the two resulting types also play nicely the same way as the original ones. Dawid