Skip to content

[Core] Split collection namespaces by mutability #351

Description

@sangkilc

Background

B2R2.Collections currently contains both immutable/function-style collections
and mutable/object-style collections.

For example, immutable collections are exposed mainly through F# modules:

RandomAccessQueue.enqueue q x
PersistentQueue.dequeue q
IntervalMap.add range value map

Mutable collections are exposed through instance members:

uniqueQueue.Enqueue x
lruCache.Add(key, value)
registerSet.Remove idx

This is not necessarily wrong, but the API style difference can look
inconsistent from the F# side. CompiledName mostly solves the C# casing issue,
but it does not clarify the API shape difference between immutable module
functions and mutable instance members.

Proposal

Split collection namespaces based on mutability:

namespace B2R2.Collections.Immutable

For persistent/immutable collections:

  • PersistentQueue
  • RandomAccessQueue
  • IntervalMap
  • IntervalSet
  • NoOverlapIntervalMap
namespace B2R2.Collections.Mutable

For stateful/mutable collections:

  • UniqueQueue
  • LRUCache
  • ConcurrentLRUCache
  • RegisterSet
  • DoublyLinkedKeyValue

Motivation

This would make the API design easier to understand:

  • Immutable collections use module functions and lowerCamelCase names in F#.
  • Mutable collections use classes and PascalCase instance members.
  • The namespace communicates the intended usage model.
  • F# users can explicitly open only the collection family they need.
  • The current module-vs-class API split becomes a meaningful design distinction
    rather than an apparent naming inconsistency.

Example

Current:

open B2R2.Collections

let q = RandomAccessQueue.empty
let q = RandomAccessQueue.enqueue q x

let uq = UniqueQueue<_>()
uq.Enqueue x

Proposed:

open B2R2.Collections.Immutable

let q = RandomAccessQueue.empty
let q = RandomAccessQueue.enqueue q x
open B2R2.Collections.Mutable

let uq = UniqueQueue<_>()
uq.Enqueue x

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions