caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: caml-list@inria.fr
Cc: Lauri Alanko <la@iki.fi>, Dan Schmidt <dfan@dfan.org>
Subject: Re: [Caml-list] Design advice
Date: Mon, 30 Sep 2002 18:03:24 +0200	[thread overview]
Message-ID: <3D9875CC.5000707@baretta.com> (raw)
In-Reply-To: <20020929122730.GA1093@la.iki.fi>



Lauri Alanko wrote:
> This doesn't help you much, but you may be interested to know that in
> Haskell this wouldn't be much of a problem. You would do simply:
> 
> data Suit = Spades | Hearts | Diamonds | Clubs
> 	deriving (Eq, Ord, Enum, Ix)
> 
> ...
> Finally, "Ix" means that the compiler generates some functionality that
> is required for a data type to be usable as an array index. And this is
> probably the feature that you seem to need. In Haskell, you could have
> an array whose _index_ type is Suit. With such an array, there's no fear
> of overflowing, because there simply _aren't_ any index values of the
> proper type that weren't included in the domain of the array.
> 
> Of course you can get the same safety in ocaml, too, but it just
> requires some more work on your part.
> 
> This isn't an unconditional plug for Haskell, mind you. Both Haskell and
> ocaml are fine languages, and each has great features that the other
> lacks.
> 
> 
> Lauri Alanko
> la@iki.fi

type tagged_type = Tag1 of foo | Tag2 of bar | ...

class ['a] tagged_array size =
object
   val map = Hashtbl.create size
   method set index value = Hashtbl.remove map index;
     Hashtbl.add map index value
   method get index = Hashtbl.find map index
   (* any other methods you might need *)
end

It's not really an array, but it's almost as fast and works 
very much like one. I think this approach might solve most 
of Dan's problems.

Alex

-------------------
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-30 15:53 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
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 [this message]
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=3D9875CC.5000707@baretta.com \
    --to=alex@baretta.com \
    --cc=caml-list@inria.fr \
    --cc=dfan@dfan.org \
    --cc=la@iki.fi \
    /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).