caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Thomas Gazagnaire <ocaml@gazagnaire.com>
To: Jacques Carette <carette@mcmaster.ca>
Cc: Hugo Ferreira <hmf@inescporto.pt>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Defining type that requires hashtables with recursive  definition
Date: Mon, 19 Jan 2009 18:03:23 +0000	[thread overview]
Message-ID: <9722eaea0901191003j7bae9032r84e46ec0bb11ae3e@mail.gmail.com> (raw)
In-Reply-To: <4974B98E.4020700@mcmaster.ca>

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

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 <carette@mcmaster.ca>

> 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
>

[-- Attachment #2: Type: text/html, Size: 2077 bytes --]

  reply	other threads:[~2009-01-19 18:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-19 17:26 Hugo Ferreira
2009-01-19 17:34 ` [Caml-list] " Jacques Carette
2009-01-19 18:03   ` Thomas Gazagnaire [this message]
2009-01-19 19:36     ` Hugo Ferreira
2009-01-20 10:09     ` Hugo Ferreira
2009-01-19 19:34   ` Hugo Ferreira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9722eaea0901191003j7bae9032r84e46ec0bb11ae3e@mail.gmail.com \
    --to=ocaml@gazagnaire.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=carette@mcmaster.ca \
    --cc=hmf@inescporto.pt \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).