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 p38HZGk7030994 for ; Fri, 8 Apr 2011 19:35:16 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnECADVGn03B/BfUc2dsb2JhbACESqFfAQwKDAcUAyKwIpBRgSmDTHgEjU6Dag X-IronPort-AV: E=Sophos;i="4.63,324,1299452400"; d="scan'208";a="80475200" Received: from msa03.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.212]) by mail3-smtp-sop.national.inria.fr with ESMTP; 08 Apr 2011 19:35:11 +0200 Received: from [192.168.1.63] ([83.204.229.18]) by mwinf5d12 with ME id V5b91g00A0QTpRf035b99L; Fri, 08 Apr 2011 19:35:10 +0200 Message-ID: <4D9F4753.5020105@frisch.fr> Date: Fri, 08 Apr 2011 19:35:15 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: Till Varoquaux CC: Andreas Rossberg , Gerd Stolpmann , Dawid Toton , caml-list References: <4D9E28D2.1050808@wp.pl> <1302212990.8429.1150.camel@thinkpad> <0F248A34-05CF-4640-B122-75C4CE7C2CD2@mpi-sws.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] What is an applicative functor? On 04/08/2011 06:43 PM, Till Varoquaux wrote: > I tend to consider using Impure functors as very poor coding hygiene.. > I am sure there are compelling use cases but I've yet to come across > one. A functor that implements hash-consing over some type could be one such example: module HashCons(X : Hashtbl.HashedType) : sig type s val mk: X.t -> s val get: s -> X.t end = struct type s = X.t module H = Hashtbl.Make(X) let tbl = H.create 16 let mk x = try H.find tbl x with Not_found -> H.add tbl x x; x let get x = x end The intention is that values of type s are physical equal whenever they wrap equal values of type t. Unfortunately, this invariant can be broken because the functor is applicative. It would be good to be able to mark it as being generative instead. Alain