Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lawful Wedge composition does not always result in a lawful Wedge #559

Open
rpiaggio opened this issue Jul 18, 2022 · 0 comments
Open

Lawful Wedge composition does not always result in a lawful Wedge #559

rpiaggio opened this issue Jul 18, 2022 · 0 comments

Comments

@rpiaggio
Copy link
Contributor

The example is a bit convoluted but illustrates the point.

I've opened a branch with a worksheet so that it's easy to reproduce.

https://github.com/gemini-hlsw/lucuma-core/blob/wedge/modules/tests/shared/src/test/scala/lucuma/core/optics/wedge.worksheet.sc

In summary, if we define:

val mirrorWedge: Wedge[Option[BigDecimal], Option[BigDecimal]] =
  Wedge(
    _.map(_.setScale(2, scala.math.BigDecimal.RoundingMode.HALF_UP)),
    _.map(_.setScale(2, scala.math.BigDecimal.RoundingMode.HALF_UP))
  )

val posBigDecimalWedge: Wedge[Option[BigDecimal], Option[PosBigDecimal]] =
  Wedge(
    _.flatMap(bd => PosBigDecimal.from(bd).toOption),
    _.map(_.value)
  )

val combinedWedge: Wedge[Option[BigDecimal], Option[PosBigDecimal]] =
  mirrorWedge.andThen(posBigDecimalWedge)

Then both mirrorWedge and posBigDecimalWedge are lawful, but combinedWedge fails normalize B.

It seems to be caused because truncation on the reverseGets turns a valid PosBigDecimal into an invalid one (when x < 0.01).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant