zio / zio-prelude

A lightweight, distinctly Scala take on functional abstractions, with tight ZIO integration
https://zio.dev/zio-prelude
Apache License 2.0
450 stars 115 forks source link

Inverse signature does not match its documentation #191

Open thesamet opened 4 years ago

thesamet commented 4 years ago

In https://github.com/zio/zio-prelude/blob/9bbfa4fd23b85b67f58b71c46ff4f7c85ab243c4/src/main/scala/zio/prelude/Inverse.scala#L10-L16:

  /**
   * Returns a right inverse for the given `A` value, such that when
   * the value is combined with the inverse (on the right hand side),
   * the identity element is returned.
   */
  def inverse(l: => A, r: => A): A

Based on the documentation and the trait's name, I would expect a function takes an A and return an A - however, looking at the instances of this typeclass, it seems like the intention of this type class is a subtraction operation, and not inversion.

adamgfraser commented 4 years ago

@thesamet Yes, we found that an Inverse operation that was the inverse of the normal associative operation and "undid" it was more general because you can describe for example subtraction on natural numbers that way whereas you can't do so purely in terms of an inverse value and the normal associative operation because negative numbers aren't in the set of natural numbers. You're right the documentation definitely needs to be updated. Will do that. Thanks for reporting!

thesamet commented 4 years ago

Thanks for the quick response, Adam. Since inverse has a different meaning in algebra, consider renaming the trait to some opposite of combine, perhaps Subtract or something like that.