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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 31E7FBC6B for ; Wed, 27 Jun 2007 17:48:46 +0200 (CEST) Received: from oden.vtab.com (dns.vtab.com [62.20.90.195]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5RFmj46009351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 27 Jun 2007 17:48:45 +0200 Received: from oden.vtab.com (oden.vtab.com [127.0.0.1]) by oden.vtab.com (Postfix) with ESMTP id 379D226EEBA; Wed, 27 Jun 2007 17:48:45 +0200 (CEST) Received: from virtutech.se (alfredo.hq.vtech [10.0.0.52]) by oden.vtab.com (Postfix) with ESMTP id 2236C26EEB0; Wed, 27 Jun 2007 17:48:45 +0200 (CEST) Received: (from mattias@localhost) by virtutech.se (8.11.6/8.11.6) id l5RFmiS04436; Wed, 27 Jun 2007 17:48:44 +0200 Date: Wed, 27 Jun 2007 17:48:44 +0200 Message-Id: <200706271548.l5RFmiS04436@virtutech.se> From: "=?iso-8859-1?q?Mattias_Engdeg=E5rd?=" To: robert.fischer@SmokejumperIT.com Cc: caml-list@yquem.inria.fr In-reply-to: <46828488.3000006@SmokejumperIT.com> (message from Robert Fischer on Wed, 27 Jun 2007 10:38:48 -0500) Subject: Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments Content-Type: text/plain; charset=iso-8859-1 References: <200706271314.35134.jon@ffconsultancy.com> <1A1D6F56-B3DB-4552-969C-9859482175AC@lrde.epita.fr> <200706271453.06045.jon@ffconsultancy.com> <200706271528.l5RFSKF04408@virtutech.se> <46828488.3000006@SmokejumperIT.com> X-Virus-Scanned: ClamAV using ClamSMTP X-j-chkmail-Score: MSGID : 468286DD.001 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 468286DD.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; mattias:01 mattias:01 compile-time:01 sig:01 val:01 val:01 struct:01 hashtbl:01 hashtbl:01 bool:01 bool:01 equality:01 caml-list:01 strings:01 expression:02 >I don't have a top-level with me right now, so I'm shooting from the >hip, but I don't think it is a compile-time error to attempt to use the >referential equality operator on two different types. No, (==) : 'a -> 'a , so this would work: module Sym : sig type t val symbol : string -> t val str : t -> string end = struct type t = string let symbol = let m = Hashtbl.create 1 in fun s -> try Hashtbl.find m s with Not_found -> (Hashtbl.add m s s; s) let str s = s end;; # "toto" == "alpha" ;; - : bool = false # Sym.symbol "alpha" == Sym.symbol "alpha" ;; - : bool = true # Sym.symbol "alpha" == "alpha" ;; Characters 22-29: Sym.symbol "alpha" == "alpha" ;; ^^^^^^^ This expression has type string but is here used with type Sym.t The cost is a slightly clumsier use of symbols as strings (Symbol.str), but my feeling is that the extra safety is worth it.