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=HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 9FC47BBAF for ; Mon, 19 Jan 2009 19:09:44 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhgCAFFQdEnRVdoLm2dsb2JhbACCQS6QWj4BAQEBAQgJCgkRviiFcw X-IronPort-AV: E=Sophos;i="4.37,290,1231110000"; d="scan'208";a="21714122" Received: from mail-bw0-f11.google.com ([209.85.218.11]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Jan 2009 19:09:41 +0100 Received: by bwz4 with SMTP id 4so1631161bwz.3 for ; Mon, 19 Jan 2009 10:09:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.181.240.10 with SMTP id s10mr92666bkr.108.1232388203311; Mon, 19 Jan 2009 10:03:23 -0800 (PST) In-Reply-To: <4974B98E.4020700@mcmaster.ca> References: <4974B7AA.9010004@inescporto.pt> <4974B98E.4020700@mcmaster.ca> Date: Mon, 19 Jan 2009 18:03:23 +0000 Message-ID: <9722eaea0901191003j7bae9032r84e46ec0bb11ae3e@mail.gmail.com> Subject: Re: [Caml-list] Defining type that requires hashtables with recursive definition From: Thomas Gazagnaire To: Jacques Carette Cc: Hugo Ferreira , caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=001636c5a8261571100460d9bdcd X-Spam: no; 0.00; hashtables:01 recursive:01 ocaml:01 recursive:01 hashtbl:01 hashedtype:01 struct:01 node:01 node:01 hash:01 hashtbl:01 hash:01 hashtable:01 beginner's:01 ocaml:01 --001636c5a8261571100460d9bdcd Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit or if you really want to define your own equality, you can use recursive modules: module rec H : Hashtbl.HashedType = struct type node = | Node of node J.t | Leaf of int type t = node let equal (e1:node) (e2:node) = (==) e1 e2 let hash (e:node) = Hashtbl.hash e end and J : Hashtbl.S = Hashtbl.Make( H ) 2009/1/19 Jacques Carette > Hugo Ferreira wrote: > >> I am attempting to define a type so: >> >> type node = >> | Node of links >> | Leaf of int >> >> And I want to implement links as a >> hashtable whose keys and values are >> also of type node. >> > > type node = > | Node of links > | Leaf of int > and links = (node, node) Hashtbl.t > > should do it. > > Jacques > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --001636c5a8261571100460d9bdcd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable or if you really want to define your own equality, you can use recursive mo= dules:

module rec H : Hashtbl.HashedType =3D
struct
 &nbs= p;  type node =3D
        | Node of n= ode J.t
        | Leaf of int

&nbs= p;   type t =3D node
    let equal (e1:node) (e2:node) =3D (=3D=3D) e1 e2
&nbs= p;   let hash (e:node) =3D Hashtbl.hash e
end

and J : H= ashtbl.S =3D Hashtbl.Make( H )

2009/1/19 = Jacques Carette <carette@mcmaster.ca>
Hugo Ferreira wrote:
I am attempting to define a type so:

type node =3D
 | Node of links
 | Leaf of int

And I want to implement links as a
hashtable whose keys and values are
also of type node.

type node =3D
 | Node of links
 | Leaf of int
and links =3D (node, node) Hashtbl.t

should do it.

Jacques


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--001636c5a8261571100460d9bdcd--