From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 4ECB6BC69 for ; Mon, 30 Jul 2007 00:44:52 +0200 (CEST) Received: from bsd4.nyct.net (mail-out8.nyct.net [216.139.141.8]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6TMioCY007428 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 30 Jul 2007 00:44:51 +0200 Received: from [192.168.42.2] (adsl-216-139-154-52.nyct.net [216.139.154.52]) by bsd4.nyct.net (8.13.4/8.13.4) with ESMTP id l6TMikWx056518; Sun, 29 Jul 2007 18:44:47 -0400 (EDT) (envelope-from bhurt@spnz.org) Date: Sun, 29 Jul 2007 18:55:02 -0400 (EDT) From: Brian Hurt X-X-Sender: bhurt@localhost To: Arnaud Spiwack Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Void type? In-Reply-To: <46ACF35F.5070102@lix.polytechnique.fr> Message-ID: References: <46AC748B.10200@lix.polytechnique.fr> <200707291216.34682.jon@ffconsultancy.com> <46AC7BB8.8050609@gmail.com> <20070729124340.GA18564@furbychan.cocan.org> <46AC8EEF.1040102@gmail.com> <20070729170216.GA8137@furbychan.cocan.org> <46ACF35F.5070102@lix.polytechnique.fr> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 46AD1862.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 segfaults:01 ocaml:01 2007,:98 wrote:01 arnaud:01 abstract:01 caml-list:01 unit:03 bugs:03 element:03 element:03 generally:04 types:05 types:05 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