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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 6FD947EE25 for ; Thu, 14 Nov 2013 12:21:12 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mshinwell@janestreet.com) identity=pra; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mshinwell@janestreet.com"; x-sender="mshinwell@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of mshinwell@janestreet.com designates 38.105.200.229 as permitted sender) identity=mailfrom; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mshinwell@janestreet.com"; x-sender="mshinwell@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@tot-dmz-mxout1.janestreet.com) identity=helo; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mshinwell@janestreet.com"; x-sender="postmaster@tot-dmz-mxout1.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al8BADGxhFImacjlnGdsb2JhbABaDoQEvyCBGR4OAQEBAQEGDQkJFCiCJQEBBUABATcBDwsLAwouIhIBBQEcBhMIh3kDAqEQiw6EUgEFjxEGjywzB4QxmBOQIBgphBQ/ X-IPAS-Result: Al8BADGxhFImacjlnGdsb2JhbABaDoQEvyCBGR4OAQEBAQEGDQkJFCiCJQEBBUABATcBDwsLAwouIhIBBQEcBhMIh3kDAqEQiw6EUgEFjxEGjywzB4QxmBOQIBgphBQ/ X-IronPort-AV: E=Sophos;i="4.93,699,1378850400"; d="scan'208";a="42725142" Received: from mx5.janestreet.com (HELO tot-dmz-mxout1.janestreet.com) ([38.105.200.229]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Nov 2013 12:21:11 +0100 Received: from tot-oib-smtp1.delacy.com ([172.27.22.15] helo=tot-smtp) by tot-dmz-mxout1.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1Vguyz-0003JM-8j for caml-list@inria.fr; Thu, 14 Nov 2013 06:21:09 -0500 Received: from tot-dmz-mxgoog1.delacy.com ([172.27.224.14] helo=mxgoog2.janestreet.com) by tot-smtp with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1Vguyz-0000dQ-7h for caml-list@inria.fr; Thu, 14 Nov 2013 06:21:09 -0500 Received: from mail-ve0-f175.google.com ([209.85.128.175]) by mxgoog2.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1Vguyz-0005HZ-4k for caml-list@inria.fr; Thu, 14 Nov 2013 06:21:09 -0500 Received: by mail-ve0-f175.google.com with SMTP id jw12so1658668veb.6 for ; Thu, 14 Nov 2013 03:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=OnrzBjHNwJaKAIhDBrHSTae7Zf0OStz+EOp7unk7Avc=; b=QwoLYjxlV3yjc5z4++00iBoZHLifXKNqJS4iulYzBpPaJ2cbH8LTB6qtkqfDixHJPE SpZoZU3IPcLwr6pBfF6h/E4/UsdZmWlN8R+DilZElx1C1hJIeffxzmFo799og5rYMpIx QKWc9PzLVm2zjwmmifXxBQAFYU1JkFxP+bcMc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=OnrzBjHNwJaKAIhDBrHSTae7Zf0OStz+EOp7unk7Avc=; b=Fsn73FybweZK0kE0cxQU+4DsNOm25gjD6OK3KgR8eSMmdGYQbEbNUnYV9bsA8LHJi5 KtVmiFPu0VLEGcSsEMPfKZFNIAXfpPjxwgeD3CK2d/Q4KbXufHuOZ631xPSA8FUVTR+D VxkAtQccW+VfCZOkFuO19pLF6P5pECFdbCUXdYqLx/uUJHHq8tgs6M7qLu4SIIZAn3VG z+++d/GJj1fEHFpxwwEmQ7B94vhzTCTavEup8jCUr4BHxIt/50JXIGaVJAumxnREE4Ns z7yjf8LbLTB7XNj7rgnCGwRGiSL0swZMvstX+zt6fGbW1scgPoJnyoj2VEsJkBF7UHoW dNkg== X-Gm-Message-State: ALoCoQlsTnrsgfYT1hRzxbghGQSTCuaYPie9/aJSoRZKh+7efLvMpvmJklSvfRR/e53Ig7v3ejit5pwrMuViDVxayVjkygG+sgzkWV44VUg6VGt7gaHSuSI9tq1Yasq3UWxRNfDAFst6jh+BUgnob/gcbTRavQ1Rzg== X-Received: by 10.52.33.147 with SMTP id r19mr288112vdi.37.1384428068972; Thu, 14 Nov 2013 03:21:08 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.52.33.147 with SMTP id r19mr288108vdi.37.1384428068877; Thu, 14 Nov 2013 03:21:08 -0800 (PST) Received: by 10.58.144.198 with HTTP; Thu, 14 Nov 2013 03:21:08 -0800 (PST) In-Reply-To: <7389AC6E-C25D-43B3-9A39-E59F92EF35AB@my.bristol.ac.uk> References: <7389AC6E-C25D-43B3-9A39-E59F92EF35AB@my.bristol.ac.uk> Date: Thu, 14 Nov 2013 11:21:08 +0000 Message-ID: From: Mark Shinwell To: Ollie Frolovs Cc: caml users Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Validation-by: mshinwell@janestreet.com Subject: Re: [Caml-list] Creating a Map from custom type On 14 November 2013 10:39, Ollie Frolovs wrote: > My current implementation uses associative lists, in subroute.ml: > > open Core.Std > type t =3D ((int list * int) * (int * int list)) list > let empty =3D [] > let to_list x =3D x > let add t k v =3D List.Assoc.add t k v > let find t k =3D List.Assoc.find t k > > I would like to use a Map instead. The key for my Map must have the type = (int list * int) and the values have the type (int * int list). If i unders= tood it correctly, because the key is a tuple and not one of the built-in s= imple data types (string, int, etc), because of this i have to provide a cu= stom comparator. This is first thing that i am not sure of. I think you need something like: module Key =3D struct type t =3D int list * int with sexp, compare end module My_map =3D Map.Make (Key) Then, for example: let map =3D My_map.add My_map.empty ~key:([42], 0) ~data:(1, [2]) The "with compare" auto-generates a "compare" function for you. Using explicit comparison functions, as Core strongly encourages, does unfortunately mean a bit more code at times but is arguably vastly more sustainable as your codebase grows. In such scenarios it becomes increasingly unlikely that the correct notion of comparison on one of your many abstract types coincides with the structural comparison on whatever implementation those types happen to have today. Mark