caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Subtyping (or something like it)
@ 2017-11-16 21:46 Reed Wilson
  2017-11-17  0:49 ` Yawar Amin
  2017-11-17 13:01 ` octachron
  0 siblings, 2 replies; 6+ messages in thread
From: Reed Wilson @ 2017-11-16 21:46 UTC (permalink / raw)
  To: caml-list

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

A while ago, I made a module which basically extended bigarrays with a few
more functions. However, I wanted to have a distinction between read-only
and read-write values. The equivalence with bigarrays was irrelevant, so my
interface just looked like this:

type ro
type rw
type 'a t
val read_only : 'a t -> ro t
val get : 'a t -> int -> int
val put : rw t -> int -> int -> unit
...

Basically, any function that wrote to the type would have to take a "rw t",
but anything else would take " 'a t". From what I know about C, "ro"
behaves like the "const" qualifier - not water-proof but it catches some of
my common mistakes.

Now, however, I want to re-export the equivalence between 'a t and
bigarrays (mostly for the .{} operator), but also have the
read-only/read-write distinction. The problem is that if I write:
type 'a t = (int, int8_unsigned_elt, c_layout) Array1.t

then OCaml will see that "ro t" and "rw t" are the same and freely let me
use "ro t" values in, for example, the "put" function above.

To summarize, is there a way to make two types internally represented by
bigarrays, the first of which:
* can use the bigarray functions (specifically .{} )
* can use all of my new functions
and the second type
* can't use bigarray functions
* can only use a subset of my new functions

I don't want to have two different versions of each function that I have to
keep track of.

Thanks,
Reed Wilson

-- 
ç

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

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

end of thread, other threads:[~2017-11-17 16:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-16 21:46 [Caml-list] Subtyping (or something like it) Reed Wilson
2017-11-17  0:49 ` Yawar Amin
2017-11-17  2:05   ` Reed Wilson
2017-11-17 13:01 ` octachron
2017-11-17 16:13   ` Reed Wilson
2017-11-17 16:32     ` Leo White

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