caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: "John Gerard Malecki" <johnm@artisan.com>, caml-list@inria.fr
Subject: Re: [Caml-list] Design advice
Date: Sat, 28 Sep 2002 16:03:20 -0700	[thread overview]
Message-ID: <4.3.2.7.2.20020928155628.03c6f400@mail.d6.com> (raw)
In-Reply-To: <15766.9898.869203.134558@spike.artisan.com>


>   type card = Number of int | Jack | Queen | King | Ace

On a related note, for Xavier et al., why wasn't Number's field 0 assigned 
to the same counter as the int of the non-argument constructors?  In other 
words, why isn't there a single incrementing int id from left to right, 
regardless of arguments?  That would have made algorithmic manipulations on 
variants easier, because then you just have:

let card_to_int (c : card) : int =
         let r = Obj.repr c in
         if Obj.is_int r then Obj.magic c else Obj.obj (Obj.field r 0);;

I don't think it's possible to write card_to_int the way the compiler 
currently works.  If there was a card_cardinality (!) function then you 
could do that + field 0 and the argument constructors would start at the 
end (still not as nice as if they were in the source code order, but better 
than nothing).  Maybe you can write that with camlp4 (of course, with 
camlp4 you can probably just write the longhand match-with form, but if 
you're doing this a lot I'd assume match-with would be slower than just 
fetching the field).

Chris


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


  reply	other threads:[~2002-09-28 23:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-27 16:47 Dan Schmidt
2002-09-28 10:48 ` John Prevost
2002-09-28 10:55 ` Chris Hecker
2002-09-28 19:02   ` William Lovas
2002-09-28 22:01     ` John Gerard Malecki
2002-09-28 23:03       ` Chris Hecker [this message]
2002-09-30 15:35       ` Kontra, Gergely
2002-09-28 22:46     ` Chris Hecker
2002-09-29 12:27 ` Lauri Alanko
2002-09-30 16:03   ` Alessandro Baretta
2002-10-01 11:37 ` Xavier Leroy

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=4.3.2.7.2.20020928155628.03c6f400@mail.d6.com \
    --to=checker@d6.com \
    --cc=caml-list@inria.fr \
    --cc=johnm@artisan.com \
    /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).