caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andreas Rossberg <rossberg@mpi-sws.org>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] A shallow option type
Date: Sat, 5 May 2012 17:07:29 +0200	[thread overview]
Message-ID: <DAD6B735-6222-4314-A56E-977596B1F23C@mpi-sws.org> (raw)
In-Reply-To: <8A61AE0A-950A-4AE0-912F-2B7A233C7E8A@mpi-sws.org>

I should add that, even if "shallow options" where easy to achieve,  
they are really a bad idea. You can witness that in "dynamic"  
languages, where the lack of types leads everybody to just use the  
equivalent of non-disjoint unions, and thus shallow options. This can  
lead to an inflation of null-like sentinel values.

Consider e.g. JavaScript. Originally, there was `null`. Then they saw  
the need to distinguish an unbound variable from one bound to null  
(i.e., distinguish `None` from `Some None`) -- and `undefined` was  
born. Fast forward, `undefined` has proliferated to all sorts of APIs,  
and there is a desire to be able to treat it as proper value in many  
places, e.g. be able to store it in maps. Now there are recurring  
discussions how to introduce other sentinel values to distinguish  
"absent" from "mapped to `undefined`".

With a properly compositional, algebraic option type this mess cannot  
arise.

/Andreas


On May 5, 2012, at 16.48 h, Andreas Rossberg wrote:

> On May 5, 2012, at 15.33 h, Goswin von Brederlow wrote:
>> What I want is a
>>
>>   type 'a shallow = NULL | 'a  (constraint 'a != 'b shallow)
>
> This is a form of negation, which cannot be expressed in  
> conventional type systems. Just consider what it should mean in the  
> presence of type abstraction: if you have
>
>  M : sig
>    type t
>    ...
>  end
>
> would `M.t shallow` be a legal type? You couldn't decide that  
> properly without requiring that _every_ abstract type in every  
> signature is annotated with a constraint saying that it is "not  
> shallow".
>
>> I have some ideas on how to implement this in a module as abstract  
>> type
>> providing get/set/clear functions, which basically means I map None  
>> to a
>> C NULL pointer and Some x to plain x. I know x can never be the NULL
>> pointer, except when someone creates a 'a shallow shallow and sets  
>> Some
>> None. That would turn into simply None.
>
> And how do you know that nobody else implements a _different_ type,  
> say shallow2, that does the same thing? And a third party then  
> constructs a value of type `int shallow2 shallow`?
>
> It seems to me that what you want effectively is a special case of  
> non-disjoint union. Unfortunately, those are known to come with all  
> kinds of problems, such as not being compositional.
>
> /Andreas
>
>
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2012-05-05 15:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-05 13:33 Goswin von Brederlow
2012-05-05 13:50 ` Gabriel Scherer
2012-05-05 14:48 ` Andreas Rossberg
2012-05-05 15:07   ` Andreas Rossberg [this message]
2012-05-05 16:22   ` Goswin von Brederlow
2012-05-05 17:11     ` Gabriel Scherer
2012-05-06 10:12       ` Goswin von Brederlow
2012-05-06 10:20     ` Goswin von Brederlow
2012-05-06 13:01 ` Jacques Garrigue
2012-05-06 15:34   ` Goswin von Brederlow
2012-05-07  0:29     ` Jacques Garrigue
2012-05-07  1:27     ` Jacques Garrigue
2012-05-07  2:34       ` Jacques Garrigue
2012-05-07  8:11       ` Jacques Garrigue
2012-05-07 17:07         ` Goswin von Brederlow
2012-05-08  0:07           ` Jacques Garrigue

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=DAD6B735-6222-4314-A56E-977596B1F23C@mpi-sws.org \
    --to=rossberg@mpi-sws.org \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    /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;
as well as URLs for NNTP newsgroup(s).