From: Brian Hurt <bhurt@spnz.org>
To: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: Void type?
Date: Sun, 29 Jul 2007 18:55:02 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0707291845160.16359@localhost> (raw)
In-Reply-To: <46ACF35F.5070102@lix.polytechnique.fr>
On Sun, 29 Jul 2007, Arnaud Spiwack wrote:
> Well, I don't really know why to use a void type in OCaml as well, thus my
> answer may be quite abstract. But when I provide a new type, I give a way to
> build it and a way to use it. In the case of the void type, there is no way
> to build an element of that type, but there is a way to use one such element
> : a void element can be used in place of any type.
This is why you can not build an element of void type (without Obj.magic)-
as there is no value which can be (safely) used as any type. Using
Obj.magic to create such void types will simply lead to segfaults and
mysterious bugs in your code, and thus nullify the main advantages of
Ocaml. The main reason I can see to use void types is to introduce
Java-style nulls into Ocaml. The lack of Java-style nulls is one of the
main reasons I like Ocaml.
If you want to have a "nullable" type, use 'a option or the equivalent.
If you want to have a "no value" type, use unit. As a general rule, if
you find yourself fighting the type system, step back, rethink the
problem, and find a solution that works with the type system and not
against it- you'll generally end up with better code.
Brian
next prev parent reply other threads:[~2007-07-29 22:44 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-28 4:14 Stefan Monnier
2007-07-28 4:33 ` [Caml-list] " Erik de Castro Lopo
2007-07-28 4:51 ` Chris King
2007-07-28 18:49 ` Stefan Monnier
2007-07-28 18:53 ` Basile STARYNKEVITCH
2007-07-29 0:48 ` Stefan Monnier
2007-07-28 18:57 ` Arnaud Spiwack
2007-07-28 6:12 ` Daniel de Rauglaudre
2007-07-28 6:15 ` Chung-chieh Shan
2007-07-28 8:22 ` [Caml-list] " rossberg
2007-07-29 6:31 ` Chung-chieh Shan
2007-07-29 11:05 ` [Caml-list] " Arnaud Spiwack
2007-07-29 11:16 ` Jon Harrop
2007-07-29 11:36 ` Arnaud Spiwack
2007-07-29 12:43 ` Richard Jones
2007-07-29 12:58 ` Arnaud Spiwack
2007-07-29 17:02 ` Richard Jones
2007-07-29 20:06 ` Arnaud Spiwack
2007-07-29 22:55 ` Brian Hurt [this message]
2007-07-30 4:40 ` skaller
2007-07-30 23:13 ` Brian Hurt
2007-07-31 8:52 ` Richard Jones
2007-07-31 13:08 ` Chris King
2007-07-31 15:27 ` Markus Mottl
2007-08-01 11:37 ` Tom
2007-08-01 16:23 ` Markus Mottl
2007-07-30 4:44 ` Geoffrey Alan Washburn
2007-07-30 13:11 ` [Caml-list] " Brian Hurt
2007-07-30 13:32 ` Christopher L Conway
2007-07-30 13:35 ` Geoffrey Alan Washburn
2007-07-30 13:41 ` [Caml-list] " Chris King
2007-07-30 17:43 ` Christophe Raffalli
2007-07-30 17:58 ` Markus Mottl
2007-07-30 14:27 ` Jeff Polakow
2007-07-28 7:58 ` Sébastien Hinderer
2007-07-28 8:13 ` [Caml-list] " Basile STARYNKEVITCH
2007-07-28 12:29 ` Christophe TROESTLER
2007-07-28 13:36 ` Brian Hurt
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.64.0707291845160.16359@localhost \
--to=bhurt@spnz.org \
--cc=aspiwack@lix.polytechnique.fr \
--cc=caml-list@yquem.inria.fr \
/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