caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kenneth Adam Miller <kennethadammiller@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Hendrik Boom <hendrik@topoi.pooq.com>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Type Encoding Format Control
Date: Tue, 18 Aug 2015 15:55:06 -0400	[thread overview]
Message-ID: <CAK7rcp_JHYATeJz3ZX7FUvJuAfFSd1W-hRnNQzZNHOAwgRJPCg@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBHjX=VR58EAdzqHQ3ObrwofUmwOf4W8s5e4K3R46HVmCg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4646 bytes --]

I wouldn't know future route in regards to the question about preferring
exceptions instead later. I wouldn't say go back and undo anything
necessarily, my idea about how this would be implemented would be an extra
annotation that allows the compiler to see that there are potential value
instances of such a type that allow excision of the tag.

In the case of my_struct, you would have instead maybe some extension to
the vernacular like:

type my_struct =
  | None
  | Some of int * int array * string where_instance 0 * [||] * "" is None

In this case, you could continue your annotation of the type my_struct with
more expressive capabilities for situations where there is more than one
hole that represents None.

I don't really believe this constitutes so much value in a language that's
already fast. It would be line noise in almost all applications, and users
might not have incentives to draw from such a language feature unless they
were pushing for improvements in some very tight loop. It was just a
curiosity.

On Tue, Aug 18, 2015 at 3:44 PM, Gabriel Scherer <gabriel.scherer@gmail.com>
wrote:

> We've discussed optimisations of ('a option) in the past. Certainly
> some things could be done, but it's unclear to me how much value there is
> in
> optimizing ('a option) specifically: what if, for example, we later
> understand that ('a, exn) result is the more general abstraction that
> we should have used instead, and rely on it heavily in libraries, will
> we de-optimize options and work on optimizing results?
>
> Note that your idea of "either a failure of a value" can be achieved,
> in some monomorphic cases (specifically when you know 'a and it has a
> product structure) by using a specific type declaration:
>
>   type my_struct =
>     | None
>     | Some of int * int array * string
>
> This will be represented as efficiently as the tuple (int * int array
> * string), yet it has a default case (or two, or another case with
> exceptions, whatever -- this is more flexible than just options). With
> inline records in 4.03 -- not yet released -- you will even be able to
> have some of the product structure mutable:
>
>   type my_struct =
>     | None
>     | Some of { mutable count : int; values : int array; name : string }
>
> On Tue, Aug 18, 2015 at 9:01 PM, Kenneth Adam Miller
> <kennethadammiller@gmail.com> wrote:
> > Well, it's not restricted to pointers - In general I would think that the
> > type annotation for Some | None would be left alone. I just used pointer
> as
> > an example because pointers exclude a value, 0x0, from the valid set. In
> > which case None is encoded as 0x0.
> >
> > Thanks for the bit about polymorphism in the context of what a compiler
> > would see - clients that do not see the hypothetical additional
> annotation
> > for that specific type to allow a format wouldn't have the augmented
> > operational needs to work on such an instance correctly. Got it!
> >
> > On Tue, Aug 18, 2015 at 2:57 PM, Hendrik Boom <hendrik@topoi.pooq.com>
> > wrote:
> >>
> >> On Tue, Aug 18, 2015 at 01:06:55PM -0400, Kenneth Adam Miller wrote:
> >> > I was wondering if cases where format control is possible in typing
> >> > constructs can allow things like restricting the implementation size
> >> > after
> >> > compilation of a specific variant type. Say, for instance that I
> wanted
> >> > to
> >> > have a malloc implementation instead of returning a Some 'a | None
> type
> >> > that compiles down to a boxed case of first a word and then the
> >> > subsequent
> >> > 'a instance, down to the 'a instance, where in the values of the word
> >> > enum
> >> > (or tag) are not present in the possibilities of the 'a instance.
> >> >
> >> > Maybe it sounds silly, but in really tight loops you want to squeeze
> for
> >> > efficiency. So I was wondering if maybe the same actual code be used
> >> > with
> >> > the same sanity of type checking, but some annotation provided at the
> >> > type
> >> > declaration to allow such optimization to take place.
> >>
> >> Let's see.  OCaml steals a bit to indicate whether a valus is a pointer
> >> or not, right?  Could that bit see duual usage for the option type?  So
> >> that if it's an optional pointer type, the bit is left off, and if it's
> >> an optional nonpointer type, it's turned on (and set to point to
> >> location zero, which the GC couls check for)?
> >>
> >> THe proble I see with this is if the 'a is passed to a generic function
> >> where iti isn't statically known where it's a pinter or not.  The
> >> conpiler will not know whether to test for absence or presence of the
> >> bit.
> >>
> >> -- hendrik
> >
> >
>

[-- Attachment #2: Type: text/html, Size: 5852 bytes --]

  reply	other threads:[~2015-08-18 19:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18 17:06 Kenneth Adam Miller
2015-08-18 18:57 ` Hendrik Boom
2015-08-18 19:01   ` Kenneth Adam Miller
2015-08-18 19:44     ` Gabriel Scherer
2015-08-18 19:55       ` Kenneth Adam Miller [this message]
2015-08-18 19:58         ` Gabriel Scherer
2015-08-20  9:10       ` Goswin von Brederlow
2015-08-20 13:08         ` Kenneth Adam Miller
2015-08-20 14:05           ` David Allsopp
2015-08-20 14:09             ` Kenneth Adam Miller
2015-08-20 14:11               ` Kenneth Adam Miller
2015-08-25 12:09 ` [Caml-list] <DKIM> " Pierre Chambart

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=CAK7rcp_JHYATeJz3ZX7FUvJuAfFSd1W-hRnNQzZNHOAwgRJPCg@mail.gmail.com \
    --to=kennethadammiller@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    --cc=hendrik@topoi.pooq.com \
    /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).