-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Currently, we expose four related types in the Pulse standard library: ref, array, slice, and ArrayPtr.ptr.
Slices and pointers can be straightforwardly converted into each other. But references, arrays, and pointers can't. You can't turn a singleton array into a reference, a reference into a pointer to a singleton slice, etc.
I think we should unify pointers and arrays, and then define references as singleton arrays. The groundwork for this is already laid in the HigherArray module, which defines arrays as subarray pointers (but does not expose this fact).
Concretely, this proposal would:
- Expose functions in HigherArray/Array/etc. to split array (references).
- Define
ref taslarray t 1. (But hide this definition behind conversion functions.) - Define
ArrayPtr.ptr tasarray t(i.e., remove the module since it's redundant now).
Pros:
- We reduce a lot of code duplication with arrays/slices/pointers. Operations like sorting/swapping etc. are defined twice.
- It becomes feasible to model output parameters as mutable references, and you can pass array fields as references.
- C code makes use of these conversions, and we would support that.
Cons:
- OCaml does not support this kind of references natively. We could either not support the conversion functions on the OCaml backend, or simulate them.
Alternatives:
- We could add type classes for array-like and singleton-like references. But that's not really feasible without monomorphization.
Metadata
Metadata
Assignees
Labels
No labels