From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id D25BD7ED7A for ; Wed, 19 Sep 2012 10:11:43 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.182 as permitted sender) identity=mailfrom; client-ip=209.85.223.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f182.google.com) identity=helo; client-ip=209.85.223.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ie0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al8CAIZ9WVDRVd+2m2dsb2JhbABFqmKRZggjAQEBAQEICQsJFCeCIAEBAQQSAiwBGxILAQMMBgULAwoNISEBAREBBQEKEgYTEhCHTgEDDAubfAkDjCWCc4UTChknAwpZiHQBBQyKLmKGQQOUDoFVgRSKA4MrFimECA X-IronPort-AV: E=Sophos;i="4.80,447,1344204000"; d="scan'208";a="156218503" Received: from mail-ie0-f182.google.com ([209.85.223.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 19 Sep 2012 10:11:42 +0200 Received: by iea17 with SMTP id 17so1859369iea.27 for ; Wed, 19 Sep 2012 01:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=VFBe/Pcu85HuODAvVfQAOH3vomFccPTDrBcdnyLywGM=; b=K7hMLFu7i5IHam/Dn7PVNQBsScDUect+TDjGGdCZ15kt0T0zcarMLSFuUrkbpJkMz5 29l5aprintLy3AVwAJacWYpT0Bj+ADeMs1DiGWH/cesvtqTofKJjTHPDYDA00JNNEh4h nF+j+f7LVpIhe1jYE8I4QsIVOfPCVldbTmlvKRv9wDb7rfG4LdIjchYx5pfx41/25JQl Fje7VGutoTPekw1Ddnx7ZJSEApfMixn2o0aY8v3bHw1h08vNWwoc3Jm0+jCDiwrgrHmt R88ZABmalUrfHEs+b7JxwaYqkQJuAKzPs1pc5SrMXW5WG3SUUsm+08Epg1w9WXL2upQi kAnA== Received: by 10.50.159.133 with SMTP id xc5mr2275247igb.34.1348042301442; Wed, 19 Sep 2012 01:11:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.194.202 with HTTP; Wed, 19 Sep 2012 01:11:00 -0700 (PDT) In-Reply-To: References: <505929CD.70206@gmail.com> From: Gabriel Scherer Date: Wed, 19 Sep 2012 10:11:00 +0200 Message-ID: To: Malcolm Matalka Cc: David House , Edgar Friendly , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Expressing module sig and impl in mli file The documentation for "destructive substitution" (with t := ...) is present in the "Language Extensions" section: http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc83 On Wed, Sep 19, 2012 at 10:00 AM, Malcolm Matalka wrote: > Ah great! What you said works! The problem I was running into was > trying to do Map.Make(Bar). Still getting used to how Core organizes > things. > > I looked around a bit on google as well but couldn't find an answer to > this: what is the difference between = and := in a 'with'? The > language reference section I looked at didn't seem to make a > distinction. > > Thanks again, > /M > > On Wed, Sep 19, 2012 at 9:51 AM, David House wrote: >> Oh, and one more thing to mention. If your identifier types are not >> strings, but you have of_string and to_string functions, then you can >> do the following: >> >> module Bar = struct >> module T = struct >> type t = ... >> let of_string = ... >> let to_string = ... >> end >> include Identifiable.Of_stringable(T) >> end >> >> module Bar : Identifiable >> >> On 19 September 2012 08:49, David House wrote: >>> So, this depends. If you have an identifier type that are internally >>> just strings, then the simplest way is as I said before: >>> >>> module Bar = String_id (* or = String, both will work *) >>> >>> module Bar : sig >>> type t >>> include Identifiable with type t := t >>> (* other operations on your Bar go here *) >>> end >>> >>> The Identifiable signature includes the Comparable signature, which >>> includes a map module. So then you have a type ['a Bar.Map.t], which >>> is a map from Bar.t's to 'a. >>> >>> If you want to use your own comparison function, then you can do the following: >>> >>> module Bar = struct >>> module T = struct >>> type t = string with sexp >>> let compare = ... >>> end >>> include T >>> include Comparable.Make(T) >>> let of_string = Fn.id >>> let to_string = Fn.id >>> end >>> >>> module Bar : sig >>> type t >>> include Comparable with type t := t (* Map module, compare, etc. *) >>> include Strinagable with type t := t (* to_string, of_string *) >>> end >>> >>> This will generate a map module that uses the comparison function you define. >>> >>> If additionally you can define a hash function, then you can do the following: >>> >>> module Bar = struct >>> module T = struct >>> type t = string with sexp >>> let compare t1 t2 = ... >>> let hash t = ... >>> end >>> include T >>> include Comparable.Make(T) >>> include Hashable.Make(T) >>> let of_string = Fn.id >>> let to_string = Fn.id >>> end >>> >>> module Bar : sig >>> type t >>> include Comparable with type t := t (* Set module, Map module, >>> compare, etc. *) >>> include Strinagable with type t := t (* to_string, of_string *) >>> include Hashable with type t := t (* hash, Table module, Hash_set >>> module, etc. *) >>> end >>> >>> And the final signature is actually equal (very nearly) to >>> Identifiable, so you'd just write: >>> >>> module Bar : Identifiable >>> >>> On 19 September 2012 08:36, Malcolm Matalka wrote: >>>> Yes I think I'm confused. In all parts of this module I want the >>>> Identifiable behaviour, but at the same time I want a Map of these >>>> identifiers to something, so this turned in to me trying to jerry-rig >>>> that rather than thinking about what I actually want. >>>> >>>> Can something that is Identifiable be the key to a Map (in Core)? Am >>>> I doing something wrong if I want that? >>>> >>>> Thanks >>>> >>>> /M >>>> >>>> On Wed, Sep 19, 2012 at 9:11 AM, David House wrote: >>>>> The standard way of doing this is as follows (note that Identifier is >>>>> changing to Identifiable in the next version, so I'll use that >>>>> terminology): >>>>> >>>>> module Bar : sig >>>>> type t = string >>>>> include Identifiable with type t := t >>>>> end >>>>> >>>>> But if this is literally what you're doing, I'm sort of confused. The >>>>> point of identifiable is that you have explicit to_string/from_string >>>>> functions and the type equality with string is not exposed. E.g. you >>>>> might want to use a different comparison function than string >>>>> equality. If you expose the type equality with string, then people are >>>>> free to use String.compare on your type, so you don't get the >>>>> abstraction you wanted. >>>>> >>>>> -- >>>>> Caml-list mailing list. Subscription management and archives: >>>>> https://sympa-roc.inria.fr/wws/info/caml-list >>>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>>>> Bug reports: http://caml.inria.fr/bin/caml-bugs >>>>> > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >