Modulelens-5.3.5Haskell2010
Data.Complex.Lens
Lenses and traversals for complex numbers
- 6 values
- Packagelens-5.3.5
- Exports10
- LanguageHaskell2010
- LicenceBSD-2-Clause
- SourceLens.hs
This isn't quite a legal Lens. Notably the
view l (set l b a) = blaw 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.
Access the magnitude of a Complex number.
(10.0 :+ 20.0) & _magnitude *~ 220.0 :+ 40.0
This isn't quite a legal Lens. Notably the
view l (set l b a) = blaw 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.
Access the phase of a Complex number.
(mkPolar 10 (2-pi) & _phase +~ pi & view _phase) ≈ 2True
This isn't quite a legal Lens. Notably the
view l (set l b a) = blaw is violated when you set a phase outside the range (-pi, pi].
The phase is always in that range when queried. So don't do that!
Otherwise, this is a perfectly cromulent Lens.