From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q396pn97021289 for ; Mon, 9 Apr 2012 08:51:50 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EALmFgk/Vujhf/2dsb2JhbABCuTyBB4IJAQEDAjIBRhALDgocEhQoIYglB7ZHkFoElWuBEoRVilCCaQ X-IronPort-AV: E=Sophos;i="4.75,393,1330902000"; d="scan'208";a="153234227" Received: from witko.kerneis.info ([213.186.56.95]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-SHA; 09 Apr 2012 08:51:44 +0200 Received: from gabriel by witko.kerneis.info with local (Exim 4.72) (envelope-from ) id 1SH8Rz-0004oa-JM; Mon, 09 Apr 2012 08:51:43 +0200 Date: Mon, 9 Apr 2012 08:51:43 +0200 From: Gabriel Kerneis To: Cedric Cellier Cc: caml-list@inria.fr Message-ID: <20120409065143.GO13251@kerneis.info> References: <20120407151452.GA12887@siouxsie> <1333949868.9770.2.camel@Nokia-N900> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1333949868.9770.2.camel@Nokia-N900> User-Agent: Mutt/1.5.20 (2009-06-14) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: gabriel@kerneis.info X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on witko.kerneis.info X-Spam-Level: X-SA-Exim-Version: 4.2.1 (built Mon, 22 Mar 2010 06:51:10 +0000) X-SA-Exim-Scanned: Yes (on witko.kerneis.info) Subject: Re: [Caml-list] Articles on using types for enhancing sw-quality? On Mon, Apr 09, 2012 at 07:37:48AM +0200, Cedric Cellier wrote: > > - Chung-chieh Shan and Oleg's "Lightweight Static Capabilities" > > presents several examples of phantom types and a general design method > > to use them to enhance program safety: > >  http://okmij.org/ftp/papers/lightweight-static-capabilities.pdf > > I attempted to read this one out of curiosity, > and it raised a question: is there a way to write > these unsafe functions (List.Unsafe.tail/head...) in pure OCaml? It depends on what you call "pure OCaml". Using the evil Obj module: let head (l : 'a list) : 'a = Obj.obj (Obj.field (Obj.repr l) 0) ;; which relies on the underlying representation (use at your own risks) and generates a call to caml_array_unsafe_get: L1: const 0 push acc 1 ccall caml_array_unsafe_get, 2 return 1 Similarly: let tail (l : 'a list) : 'a list = Obj.obj (Obj.field (Obj.repr l) 1) ;; Best, -- Gabriel