From: Gabriel Kerneis <kerneis@pps.jussieu.fr>
To: Cedric Cellier <rixed@happyleptic.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Articles on using types for enhancing sw-quality?
Date: Mon, 9 Apr 2012 08:51:43 +0200 [thread overview]
Message-ID: <20120409065143.GO13251@kerneis.info> (raw)
In-Reply-To: <1333949868.9770.2.camel@Nokia-N900>
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
next prev parent reply other threads:[~2012-04-09 6:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-07 15:14 oliver
2012-04-07 16:45 ` Gabriel Scherer
2012-04-09 5:37 ` Cedric Cellier
2012-04-09 6:51 ` Gabriel Kerneis [this message]
2012-04-09 7:11 ` Gabriel Scherer
2012-04-09 17:43 ` oliver
2012-04-08 9:46 ` Daniel Bünzli
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=20120409065143.GO13251@kerneis.info \
--to=kerneis@pps.jussieu.fr \
--cc=caml-list@inria.fr \
--cc=rixed@happyleptic.org \
/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