From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p381YsAZ018816 for ; Fri, 8 Apr 2011 03:34:54 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsEBAO5knk3U436rkGdsb2JhbACES6FGFAEBAQEJCQ0HFAMiiHmmPZEZAoEng0x4BIhciFg X-IronPort-AV: E=Sophos;i="4.63,321,1299452400"; d="scan'208";a="96531008" Received: from moutng.kundenserver.de ([212.227.126.171]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Apr 2011 03:34:49 +0200 Received: from office1.lan.sumadev.de (dslb-094-219-218-046.pools.arcor-ip.net [94.219.218.46]) by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis) id 0MDgeU-1Q8Xkd0BCg-00H9Uw; Fri, 08 Apr 2011 03:34:41 +0200 Received: from [192.168.5.106] (dslb-094-219-218-046.pools.arcor-ip.net [94.219.218.46]) by office1.lan.sumadev.de (Postfix) with ESMTPA id A48FA5F701; Fri, 8 Apr 2011 03:34:40 +0200 (CEST) From: Gerd Stolpmann To: Dawid Toton Cc: caml-list In-Reply-To: <4D9E5A80.3010902@wp.pl> References: <4D9E28D2.1050808@wp.pl> <1302212990.8429.1150.camel@thinkpad> <4D9E5A80.3010902@wp.pl> Content-Type: text/plain; charset="UTF-8" Date: Fri, 08 Apr 2011 03:34:39 +0200 Message-ID: <1302226479.8429.1154.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:QtFMqdD9sEZYK39IEoFV2QIq4YmgH64oHYveBuDQzGS BJnW8PPRgYqn00J8f6/wR4ZTMxgZzuqS9o9wPV3uubfhvogbqJ Qzn3O2eC1pKtyZD9u51u2UKEyM0DmpY/ynj8HrSt9R2QOoYand Z5JuZ9lYy29uiLR2rYTgvwTs7XX46ZoUMuVM/7MrUfLgBHSWto vn4LSsmkwmJWv1lSEJavg== Subject: Re: [Caml-list] Re: What is an applicative functor? Am Freitag, den 08.04.2011, 02:44 +0200 schrieb Dawid Toton: > 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 Because the input module is not the same. It relies on module paths to check identities. > > Compare this with: > > > > module Make(X : sig end) = struct type t = Variant end > > module M1 = Make(struct end) > > module M2 = Make(struct end) My error. This is of course not the same effect. > > > > 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? I think so. I remembered it the wrong way. There is a paper from XL about this, see [5] in http://caml.inria.fr/about/papers.en.html. Gerd > > >> 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 > -- ------------------------------------------------------------ Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------