Skip to content
This repository was archived by the owner on Feb 8, 2022. It is now read-only.
This repository was archived by the owner on Feb 8, 2022. It is now read-only.

"Vector" instances are questionable #148

Description

@johnynek

@non @tixxit and I were talking about mapVectorEq and for instance the Group on Map[K, V] that assumes that a missing key is the same as Group.empty.

This has some issues. Without the correct Eq[Map[K, V]] in scope, you violate the laws. Moreover, the standard Eq should not be one that has this behavior, because that does not make sense for a lot of use cases.

Our solution is to wrap such instances:

// infinite map defined at all keys K
trait SparseMap[K, V] {
  def get(k: K): V
  def updated(k: K, v: V): SparseMap[K, V]
  def toMap: Map[K, V]
}

// an infinite vector that is defined at all points (i: Int)
trait SparseVector[T] {
  def apply(i: Int): T
  def updated(i: Int, v: T): SparseVector[T]
  def toVector: Vector[T]
}

In this way #126 would be an instance on SparseMap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions