From: Edgar Friendly <thelema314@gmail.com>
To: Pierre Weis <pierre.weis@inria.fr>
Cc: caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Compiler feature - useful or not?
Date: Wed, 14 Nov 2007 10:57:03 -0600 [thread overview]
Message-ID: <473B28DF.2050705@gmail.com> (raw)
In-Reply-To: <20071114075827.GA24058@yquem.inria.fr>
Pierre Weis wrote:
> In the next version of the compiler, you will have an extension to the
> definition of types with private construction functions (aka ``private''
> types) that just fulfills your programming concern: in addition to usual
> private sum and record private type definitions, you can now define a type
> abbreviation which is private to the implementation part of a module (see
> note 1).
>
At first glance, this improvement does satisfy my concerns, but I think
it still falls short of optimal in ways that seem easy to fix.
> Since the values of a private type are concrete, it is much easier for the
> programmer to use the values of the type abbreviation.
>
This concerns me - I'd like to require explicit casting/coercion to
create or use the internal value of the abstract type, maybe with an
exception for literals. Could you elaborate on this?
> This solution does not require any additional tagging or boxing, only the
> usage of injection/projection function for the type. As for usual private
> types, the injection function is handy to provide useful invariants (in the
> row type example case, we get ``a row value is always a positive integer'').
>
With a bit of low-level support, I imagine it not difficult to implement
the following:
type row = private int constraint (fun i -> i >= 0)
such that the compiler uses the provided constraint function to check
any (x :> row) casts, throwing an exception(?) on false. This solution
wouldn't involve the module system just to have positive integer types,
and gets rid of the function call overhead on 'from'.
> In addition, the private abbreviation is publicly exposed in the interface
> file. Hence, the compiler knows about it: it can (and effectively does)
> optimize the programs that use values of type row in the same way as if the
> type row were defined as a regular public abbreviation.
>
Does this mean I can do:
let one (r:row) = r+1
let onea (r : row) = r = 1
let two (r:row) (i:int) = r+i
let three : row -> string = function 3 -> "three" | _ -> "not three"
> Last but not least, being an instance of the identity function, the from
> projection function is somewhat generic: we can dream to suppress the burden
> of having to write it for each private type definition, if we find a way to
> have it automatically associated to the new private type by the compiler.
>
The use case for this feature is restricted construction to enforce
invariants, no? Anything more complex should probably be totally
abstract and not simply private. In which case, the constraint keyword
seems an effective way to tell the compiler what to do, and just let :>
coercions do their magic.
E.
next prev parent reply other threads:[~2007-11-14 16:57 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-13 23:41 Edgar Friendly
2007-11-14 0:08 ` [Caml-list] " Yaron Minsky
2007-11-14 0:21 ` Martin Jambon
2007-11-14 7:58 ` Pierre Weis
2007-11-14 12:37 ` Alain Frisch
2007-11-14 13:56 ` Virgile Prevosto
2007-11-14 14:35 ` Pierre Weis
2007-11-14 16:38 ` Alain Frisch
2007-11-14 18:43 ` Pierre Weis
2007-11-14 19:19 ` Edgar Friendly
2007-11-15 6:29 ` Alain Frisch
2007-11-15 13:26 ` Pierre Weis
2007-11-15 17:29 ` Edgar Friendly
2007-11-15 20:28 ` Fernando Alegre
2007-11-16 0:47 ` Brian Hurt
2007-11-15 22:37 ` Michaël Le Barbier
2007-11-15 22:24 ` Michaël Le Barbier
2007-11-16 0:30 ` Yaron Minsky
2007-11-16 1:51 ` Martin Jambon
2007-11-16 9:23 ` Alain Frisch
2007-11-16 14:17 ` rossberg
2007-11-16 15:08 ` Martin Jambon
2007-11-16 16:43 ` Martin Jambon
2007-11-16 16:46 ` Till Varoquaux
2007-11-16 17:27 ` Edgar Friendly
2007-11-16 17:47 ` Martin Jambon
2007-11-16 17:54 ` Edgar Friendly
2007-11-16 18:10 ` Fernando Alegre
2007-11-16 19:18 ` David Allsopp
2007-11-16 19:32 ` Fernando Alegre
2007-11-16 19:50 ` Gerd Stolpmann
2007-11-16 17:31 ` Fernando Alegre
2007-11-16 17:43 ` Edgar Friendly
2007-11-16 0:46 ` Christophe TROESTLER
2007-11-16 8:23 ` Andrej Bauer
2007-11-16 8:58 ` Jean-Christophe Filliâtre
2007-11-16 9:13 ` Andrej Bauer
2007-11-16 9:48 ` Christophe TROESTLER
2007-11-14 16:57 ` Edgar Friendly [this message]
2007-11-14 21:04 ` Pierre Weis
2007-11-14 22:09 ` Edgar Friendly
2007-11-15 0:17 ` Jacques Garrigue
2007-11-15 6:23 ` Edgar Friendly
2007-11-15 10:53 ` Vincent Hanquez
2007-11-15 13:48 ` Jacques Carette
2007-11-15 14:43 ` Jon Harrop
2007-11-15 16:54 ` Martin Jambon
2007-11-14 16:09 ` Edgar Friendly
2007-11-14 16:20 ` Brian Hurt
2007-11-14 11:01 ` Gerd Stolpmann
2007-11-14 10:57 ` Jon Harrop
2007-11-14 14:37 ` Zheng Li
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=473B28DF.2050705@gmail.com \
--to=thelema314@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=pierre.weis@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