caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Tuples (covariant immutable arrays)
@ 2012-03-14 20:38 Lukasz Stafiniak
  2012-03-14 21:03 ` Edgar Friendly
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Stafiniak @ 2012-03-14 20:38 UTC (permalink / raw)
  To: Caml

Hi,

Does anyone have a Tuple module that exports arrays as immutable and covariant?

Thanks,
Łukasz


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Tuples (covariant immutable arrays)
  2012-03-14 20:38 [Caml-list] Tuples (covariant immutable arrays) Lukasz Stafiniak
@ 2012-03-14 21:03 ` Edgar Friendly
  2012-03-14 21:12   ` Lukasz Stafiniak
  0 siblings, 1 reply; 5+ messages in thread
From: Edgar Friendly @ 2012-03-14 21:03 UTC (permalink / raw)
  To: Lukasz Stafiniak; +Cc: Caml

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

Batteries has a Cap submodule that provides type-level protection for
arrays so they can be Read-only/Write-only/Read-write.  The same idea with
a variance annotation and just read-only access seems to be what you're
looking for, no?

2012/3/14 Lukasz Stafiniak <lukstafi@gmail.com>

> Hi,
>
> Does anyone have a Tuple module that exports arrays as immutable and
> covariant?
>
> Thanks,
> Łukasz
>
>
> --
> 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
>
>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Tuples (covariant immutable arrays)
  2012-03-14 21:03 ` Edgar Friendly
@ 2012-03-14 21:12   ` Lukasz Stafiniak
  2012-03-14 21:26     ` Edgar Friendly
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Stafiniak @ 2012-03-14 21:12 UTC (permalink / raw)
  To: Edgar Friendly; +Cc: Caml

On Wed, Mar 14, 2012 at 10:03 PM, Edgar Friendly <thelema314@gmail.com> wrote:
> Batteries has a Cap submodule that provides type-level protection for arrays
> so they can be Read-only/Write-only/Read-write.  The same idea with a
> variance annotation and just read-only access seems to be what you're
> looking for, no?

It seems no, because Cap is invariant, and for a reason: for example,
Hashtbl.Cap.of_table says
"This operation involves no copying. In other words, in let cap =
of_table a in ..., any modification in a will also have effect on cap
and reciprocally."

What I'm thinking about is  type +'a Tuple.t with Tuple.of_list and
Tuple.of_array both performing a copy.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Tuples (covariant immutable arrays)
  2012-03-14 21:12   ` Lukasz Stafiniak
@ 2012-03-14 21:26     ` Edgar Friendly
  2012-03-14 22:18       ` Alexandre Pilkiewicz
  0 siblings, 1 reply; 5+ messages in thread
From: Edgar Friendly @ 2012-03-14 21:26 UTC (permalink / raw)
  To: Lukasz Stafiniak; +Cc: Caml

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

Ok, trivial enough a change.  You'll have to make a case for the usefulness
of this data structure being in batteries for us to make the change,
otherwise, feel free to use the batteries code as a basis for your Tuple
data structure.  LGPL2.1+linking exception should be sufficiently liberal
for most uses.

E.

btw, link to the docs I meant to include in my first email:
http://ocaml-batteries-team.github.com/batteries-included/hdoc/BatArray.Cap.html

On Wed, Mar 14, 2012 at 5:12 PM, Lukasz Stafiniak <lukstafi@gmail.com>wrote:

> On Wed, Mar 14, 2012 at 10:03 PM, Edgar Friendly <thelema314@gmail.com>
> wrote:
> > Batteries has a Cap submodule that provides type-level protection for
> arrays
> > so they can be Read-only/Write-only/Read-write.  The same idea with a
> > variance annotation and just read-only access seems to be what you're
> > looking for, no?
>
> It seems no, because Cap is invariant, and for a reason: for example,
> Hashtbl.Cap.of_table says
> "This operation involves no copying. In other words, in let cap =
> of_table a in ..., any modification in a will also have effect on cap
> and reciprocally."
>
> What I'm thinking about is  type +'a Tuple.t with Tuple.of_list and
> Tuple.of_array both performing a copy.
>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Tuples (covariant immutable arrays)
  2012-03-14 21:26     ` Edgar Friendly
@ 2012-03-14 22:18       ` Alexandre Pilkiewicz
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Pilkiewicz @ 2012-03-14 22:18 UTC (permalink / raw)
  To: Edgar Friendly; +Cc: Lukasz Stafiniak, Caml

type +'a t = (int -> 'a) * int

let get (a: 'a t) i = (fst a) i
let length (a: 'a t) = snd a

let of_array (a: 'a array) : 'a t =
  let a' = Array.copy a in
  (Array.get a', Array.length a')


should be enough

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-03-14 22:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-14 20:38 [Caml-list] Tuples (covariant immutable arrays) Lukasz Stafiniak
2012-03-14 21:03 ` Edgar Friendly
2012-03-14 21:12   ` Lukasz Stafiniak
2012-03-14 21:26     ` Edgar Friendly
2012-03-14 22:18       ` Alexandre Pilkiewicz

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).