caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: brogoff@speakeasy.net
To: Oleg Trott <oleg_trott@columbia.edu>
Cc: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Strange physical equality behavior
Date: Tue, 11 Nov 2003 09:08:13 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0311110858530.31364-100000@grace.speakeasy.net> (raw)
In-Reply-To: <200311110148.22096.oleg_trott@columbia.edu>

On Tue, 11 Nov 2003, Oleg Trott wrote:
> On Sunday 09 November 2003 08:33 pm, Jacques Garrigue wrote:
> > The functorial approach offers a much cleaner solution.
>
> I'm not convinced.
>
> With non-functorial sets:
>
> type t = Leaf of string | Node of t Set.t
>
> How would you do this with functorial sets? Perhaps like this:
>
> http://groups.google.com/groups?selm=fa.dlqsupe.1c6ajga%40ifi.uio.no
>
>     module A : sig
>                  type t = Leaf of string | Node of ASet.t
>                  val compare: t -> t -> int
>                end
>              = struct
>                  type t = Leaf of string | Node of ASet.t
>                  let compare t1 t2 =
>                    match (t1, t2) with
>                      (Leaf s1, Leaf s2) -> Pervasives.compare s1 s2
>                    | (Leaf _, Node _) -> 1
>                    | (Node _, Leaf _) -> -1
>                    | (Node n1, Node n2) -> ASet.compare n1 n2
>                end
>     and ASet : Set.S with type elt = A.t
>              = Set.Make(A)
>
> (BTW, that example doesn't yet work in 3.07-2 default toplevel. And couldn't
> one write "let compare = Pervasives.compare" above? )

 module rec A : (* a forgotten "rec" inserted *)
    sig
      type t = Leaf of string | Node of ASet.t
      val compare: t -> t -> int
    end
    = struct
      type t = Leaf of string | Node of ASet.t
      let compare t1 t2 =
        match (t1, t2) with
          (Leaf s1, Leaf s2) -> Pervasives.compare s1 s2
        | (Leaf _, Node _) -> 1
        | (Node _, Leaf _) -> -1
        | (Node n1, Node n2) -> ASet.compare n1 n2
    end
and ASet : Set.S with type elt = A.t
      = Set.Make(A)

It's a simple syntax error. And, if we use Pervasives.compare, we don't know
for sure how the Leaf <-> Node comparison will work, do we? What if it's
dependent on the order of occurrence of those constructors in the type
definition?

Functors can be heavy, but I prefer that approach too. Having a bit of
recursiveness in the module language makes them much nicer. Now if we can
just get generics...

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      parent reply	other threads:[~2003-11-11 17:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-09 18:34 Oleg Trott
2003-11-10  1:33 ` Jacques Garrigue
2003-11-10  2:25   ` Oleg Trott
2003-11-10  8:29     ` Jacques Garrigue
2003-11-10 18:41       ` Michal Moskal
2003-11-11  1:35         ` Jacques Garrigue
2003-11-11  6:48   ` Oleg Trott
2003-11-11 16:46     ` David Brown
2003-11-12  0:32       ` William Lovas
2003-11-11 17:08     ` brogoff [this message]

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=Pine.LNX.4.44.0311110858530.31364-100000@grace.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=garrigue@kurims.kyoto-u.ac.jp \
    --cc=oleg_trott@columbia.edu \
    /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).