Portability | non-portable |
---|---|

Stability | experimental |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Safe Haskell | Safe-Inferred |

Lenses and traversals for complex numbers

- _realPart :: Simple Lens (Complex a) a
- _imagPart :: Simple Lens (Complex a) a
- _polar :: RealFloat a => Simple Iso (Complex a) (a, a)
- _magnitude :: RealFloat a => Simple Lens (Complex a) a
- _phase :: RealFloat a => Simple Lens (Complex a) a
- _conjugate :: RealFloat a => Simple Iso (Complex a) (Complex a)
- complex :: Traversal (Complex a) (Complex b) a b

# Documentation

_polar :: RealFloat a => Simple Iso (Complex a) (a, a)Source

This isn't *quite* a legal lens. Notably the

`view`

l (`set`

l b a) = b

law is violated when you set a `polar`

value with 0 `magnitude`

and non-zero
`phase`

as the `phase`

information is lost, or with a negative `magnitude`

which flips the `phase`

and retains a positive `magnitude`

. So don't do
that!

Otherwise, this is a perfectly cromulent `Lens`

.

_magnitude :: RealFloat a => Simple Lens (Complex a) aSource

Access the `magnitude`

of a `Complex`

number

`>>>`

20.0 :+ 40.0`(10.0 :+ 20.0) & _magnitude *~ 2`

This isn't *quite* a legal lens. Notably the

`view`

l (`set`

l b a) = b

law is violated when you set a negative `magnitude`

. This flips the `phase`

and retains a positive `magnitude`

. So don't do that!

Otherwise, this is a perfectly cromulent `Lens`

.

Setting the `magnitude`

of a zero `Complex`

number assumes the `phase`

is 0.

_phase :: RealFloat a => Simple Lens (Complex a) aSource

Access the `phase`

of a `Complex`

number

`>>>`

True`(mkPolar 10 (2-pi) & _phase +~ pi & view _phase) ≈ 2`

This isn't *quite* a legal lens. Notably the

`view`

l (`set`

l b a) = b

law is violated when you set a `phase`

outside the range `(-`

.
The phase is always in that range when queried. So don't do that!
`pi`

, `pi`

]

Otherwise, this is a perfectly cromulent `Lens`

.